2 Replies Latest reply on Jul 5, 2006 7:34 AM by Peter Lorent

    My first class

    NSurveyor Level 2
      Hi. I finally started learning OOP and classes and such. I'm making my own number class. Anyways to make it better? Here it is so far...
        • 1. Re: My first class
          Level 7
          NSurveyor,

          > Hi. I finally started learning OOP and classes and such.

          Cool. :)

          > I'm making my own number class. Anyways to make it
          > better? Here it is so far...
          >
          > class Number2 {
          > var fact:Array;
          > var tVal:Number;
          > // etc.

          You've got some very nice algorithms in there, NSurveyor. Have you
          considered making these class members static?


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: My first class
            Peter Lorent Level 2
            Without access control modifiers every property and method is considered public. It's considered good practice to use the access control modifiers. Constructor is always public (unless you use a design pattern like Singleton).
            private var fact:Array; //or public

            Consistently type your vars: (otherwise no datatype checking)
            function factorSum(){
            var p:Number = 1;

            When a method returns a value you should specify the return type: (otherwise no datatype checking)
            function factorSum():Number{
            //code
            return p;
            When a method doesn't return anything specify Void as the return type. The contructor can't specify a return type.

            var i;
            for(i=0;i<fact.length;i++){
            You can use:
            for(var i=0;i<fact.length;i++){ //without typing var i as a Number