18: Creating an Initialize Operation

  1. Every class must have an initialization operations except for abstract classes.
    1. The initialization procedure may set properties appropriately, or it may do nothing.
    2. There are many things that an initialization procedure may not do, such as calling an object's own operations before initialization.
    3. If a concrete class has no initialization operation defined, its initialization defaults to a simple escalation.
    4. An abstract class doesn't require an initialization operation, but it may provide one if you wish.
  2. When a class is instantiated, its initialization procedure is automatically called by the engine.
  3. The initialization method must escalate.
    1. In initialization, the initialize operation escalates to all of a class's superclasses, including mix-ins.
    2. This escalation ensures that each superclass of a class sets its own properties (and hence state) appropriately.
    3. The escalation order matches the canonical search order described in the last chapter.
  4. 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.
    1. An initialization procedure must use argument identifiers to pull arguments off the stack.
    2. An initialization method must make sure there are enough arguments on the stack for escalation and that the arguments are in the proper order.
  5. An initialization method must request escalation at the proper place in its algorithms.
    1. The method typically takes off any args it needs, then escalates, then performs any other actions necessary for class initialization.
    2. Operations in the class don't work until after initialization escalation, so you can't put them before the escalation.
  6. Special considerations for the initialize operation interface:
    1. 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.
    2. 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.
    3. 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.