Changeset 2335 for cobra/trunk/HowTo/150-DeclareInits.cobra
- Timestamp:
- 03/20/10 04:42:28 (2 years ago)
- Files:
-
- 1 modified
-
cobra/trunk/HowTo/150-DeclareInits.cobra (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/HowTo/150-DeclareInits.cobra
r2127 r2335 8 8 9 9 cue init 10 # code10 # statements 11 11 12 12 cue init(ARG as TYPE) 13 # code13 # statements 14 14 15 15 cue init(ARG1 as TYPE1, ARG2 as TYPE2) 16 # code 16 # statements 17 18 Where the first statement is call to another initializer in the same class or 19 the base class: 17 20 18 21 Some key points: … … 20 23 * You can have 0 or more arguments. 21 24 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. 24 30 25 31 * Initializers can be overloaded by the number and type of their arguments. … … 27 33 * Initializers are public by default. 28 34 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. 30 37 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. 32 40 33 41 * Initializers can have their own unit tests just like methods. … … 94 102 get age from var as int 95 103 104 105 class Program 106 96 107 def main 97 108 pass



