Instances
A Class is generally used as a blueprint or model from which one or more Instances of the Class are constructed. Note however that a class can have Shared members which can be used directly without first creating an instance.
You create an instance of a Class using the ⎕NEW
system function which is monadic.
The 1-or 2-item argument to ⎕NEW
contains a reference to the Class and, optionally, arguments for its Constructor function.
When ⎕NEW
executes, it creates a regular APL namespace to contain the Instance, and within that it creates an Instance space, which is populated with any Instance Fields defined by the class (with default values if specified), and pointers to the Instance Method and Property definitions specified by the Class.
If a monadic Constructor is defined, it is called with the arguments specified in the second item of the argument to ⎕NEW
. If ⎕NEW
was called without Constructor arguments, and the class has a niladic Constructor, this is called instead.
The Constructor function is typically used to initialise the instance and may establish variables in the instance namespace.
The result of ⎕NEW
is a reference to the instance namespace. Instances of Classes exhibit the same set of Properties, Methods and Fields that are defined for the Class.