Contents | Prev | Next | Index
A class method is a method that operates on class members. For each class member there is only one instance during runtime. By contrast, regular methods operate on instance members. Instance members are newly created for each instance of a class. Canterbury Pascal always maps class methods to Java-static methods. Notice, that this approach is different from Borland Pascal, where class methods are treated like members of a metaclass. Unlike Canterbury Pascal, Borland Object Pascal does not base its classes on Java classes.
The definition of a class method must include the reserved word CLASS before the PROCEDURE or FUNCTION keyword that starts the definition. Thus, in a class type declaration, it is introduced as shown in the following language grammar:
method_def ::= method_heading ; method_directives method_heading ::= class_directive procedure_heading |
And the defining declaration of a class method must conform to the following language grammar:
procedure_decl ::= class_directive procedure_heading ; subroutine func_decl ::= class_directive func_heading ; subroutine class_directive ::= CLASS |
Example:
TYPE
TFigure = CLASS
PUBLIC
CLASS FUNCTION Supports
( Operation : STRING ) : BOOLEAN;
CLASS PROCEDURE GetInfo
( VAR Info : TFigureInfo );
END;
The defining declaration of a class method must also start with the reserved word CLASS. Example:
CLASS PROCEDURE TFigure.GetInfo
( VAR Info : TFigureInfo );
BEGIN
:
END;
In the defining declaration of a class method, the identifier SELF represents the class for which the method was activated. The type of SELF in a class method is CLASS OF class type, where class type is the class type for which this method is implemented. SELF does not represent an object reference in a class method. Hence it is not possible to access instance members. A class method can be invoked through an object reference or a class reference. In the case of an invocation through an object reference, the class of the given object reference is passed as the SELF parameter.
Contents | Prev | Next | Index
Canterbury Pascal for JVM (Last documentation update
Sep 02, 2004)
Copyright © 1999-2004 J.Neuhoff - mhccorp.com
. All rights reserved.
Please send any comments or corrections to
neuhoff@mhccorp.com