[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Initializer Methods
If a class defines a method named init, that method will be invoked
automatically when new objects of that class are created. The init
method is referred to as an initializer method. Its purpose is to
initialize a new object to a valid initial state, usually based on
arguments supplied to the constructor.
When writing the code for an initializer, if the class has a superclass,
it is usually necessary to invoke the superclass' constructor to
initialize the part of the object defined by the superclass. Class(y)
provides an automatic mechanism for doing this. The METHOD definition
command has an extended form which allows a second parameter list to be
included. Including this second parameter list causes the corresponding
superclass method to be invoked first, with the specified parameters. The
syntax for this is as follows:
METHOD <name>(<params,...>), [<superName>](<superParm,...>)]
where:
<name> is the name of the initializer method.
<params> the parameters which the method expects to receive.
<superName> is the name of the superclass' initializer. This can and
should be omitted when the superclass method being invoked has
the same name as the method being defined. In particular, when
defining an init method it is not necessary to specify the
name of the superclass method unless it is other than init.
<superParm> are the parameters expected by the superclass' constructor.
These would typically be a subset of the first parameter list.
Sometimes a subclass may not need to perform any work to initialize itself
(perhaps because it has no instance variables). In such cases, it is not
necessary to define an initializer for that class. If a superclass defines
an initializer, it will be inherited by the subclass and used during
initialization.
See Also:
Constructor Messages
METHOD (definition)
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson