18: Creating an Initialize Operation
- Every class must have an initialization operations except for abstract classes.
- The initialization procedure may set properties appropriately, or it may do nothing.
- There are many things that an initialization procedure may not do, such as calling an object's own operations before initialization.
- If a concrete class has no initialization operation defined, its initialization defaults to a simple escalation.
- An abstract class doesn't require an initialization operation, but it may provide one if you wish.
- When a class is instantiated, its initialization procedure is automatically called by the engine.
- The initialization method must escalate.
- In initialization, the initialize operation escalates to all of a class's superclasses, including mix-ins.
- This escalation ensures that each superclass of a class sets its own properties (and hence state) appropriately.
- The escalation order matches the canonical search order described in the last chapter.
- The arguments supplied for initialization must put enough arguments on the stack to supply values in the proper order for all levels of escalated initialization.
- An initialization procedure must use argument identifiers to pull arguments off the stack.
- An initialization method must make sure there are enough arguments on the stack for escalation and that the arguments are in the proper order.
- An initialization method must request escalation at the proper place in its algorithms.
- The method typically takes off any args it needs, then escalates, then performs any other actions necessary for class initialization.
- Operations in the class don't work until after initialization escalation, so you can't put them before the escalation.
- Special considerations for the initialize operation interface:
- Any identified argument in the signature is pulled off the stack before escalation, whether the argument is used or not within the class's initialization method.
- If an argument's identifier matches the identifier of a property of the class (including those created for attributes), the property is set to the value passed by that argument. This is a special case for initialization, and does not occur in any other kind of operation.
- Any unidentified arguments are not pulled off the stack before escalation.
TS Ref - 26 JUN 1996
Generated by the sweat of Mike Boom's brow.