[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Constructor Messages and Methods
------------------------------------------------------------------------------
Constructors messages are used to create new instances of a class. A
constructor method is declared in the class declaration with a
statement of the following form:
METHOD <methodName> CONSTRUCTOR
or:
METHOD <methodName> CTOR // abbreviated form
When a constructor message is sent to a class object, before invoking
the code of the associated constructor method, a new instance of that
class is created by the Class(y) kernel. Once this has been done, the
constructor method behaves like a normal method in that it has a self
which is an instance of a class. Once the method's code has been
executed, a reference to self is returned to the caller. This is
done automatically by the Class(y) kernel - the method code itself
should just perform a simple RETURN.
When writing the code for a constructor, if the class has a superclass,
it is necessary to invoke the superclass' constructor to perform
initialization of the part of the object which belongs to the
superclass. Class(y) provides an automatic mechanism for doing this.
The definition of a constructor allows a second parameter list to be
included, which is passed up to the superclass constructor before
executing the method code.
The CONSTRUCTOR method definition command is used to assist with
this automatic chaining of superclass constructors. See the entry for
the CONSTRUCTOR command for more details.
See Also:
CONSTRUCTOR
METHOD
■ new
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson