Wiki
Show
Ignore:
Timestamp:
03/20/10 04:42:28 (2 years ago)
Author:
Chuck.Esterbrook
Message:

Improvements to the How-To's.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/HowTo/150-DeclareInits.cobra

    r2127 r2335  
    88 
    99    cue init 
    10         # code 
     10        # statements 
    1111 
    1212    cue init(ARG as TYPE) 
    13         # code 
     13        # statements 
    1414 
    1515    cue init(ARG1 as TYPE1, ARG2 as TYPE2) 
    16         # code 
     16        # statements 
     17 
     18Where the first statement is call to another initializer in the same class or 
     19the base class: 
    1720 
    1821Some key points: 
     
    2023    * You can have 0 or more arguments. 
    2124 
    22     * If you declare no initalizers at all for a given class, Cobra will 
    23       provide one, public, parameterless initializer. 
     25    * If you declare no initializers at all, Cobra will automatically provide 
     26      them to match each non-private initializer in the base class. 
     27 
     28    * If you declare even one initializer, Cobra will not automatically add any 
     29      more. This gives you control over how a class must be initialized. 
    2430 
    2531    * Initializers can be overloaded by the number and type of their arguments. 
     
    2733    * Initializers are public by default. 
    2834 
    29     * Initializers can say "base.init(ARGS)" to invoke a base init. 
     35    * Initializers can say "base.init" or "base.init(ARGS)" to invoke 
     36      a base initializer. 
    3037 
    31     * Initializers can say ".init" or ".init(ARGS)" to invoke a fellow init. 
     38    * Initializers can say ".init" or ".init(ARGS)" to invoke 
     39      a fellow initialier. 
    3240 
    3341    * Initializers can have their own unit tests just like methods. 
     
    94102    get age from var as int 
    95103 
     104 
     105class Program 
     106 
    96107    def main 
    97108        pass