Statement CLASS METHOD (Declaration) Foundation
Declaring class methods (methods of the class object)
CLASS METHOD <MethodName,...>
CLASS METHOD <MessageName> [IS <MethodName>] [IN <SuperClass>]
CLASS METHOD declares a method as a class method within the class declaration (CLASS...ENDCLASS). Class methods are executed only from the class object. When an instance object receives the message for a class method, it forwards the message on to the class object.
The source code for a class method is generally implemented after the statement ENDCLASS. The code for the class method is prefaced by the declaration CLASS METHOD <MethodName>. If the class method is already implemented in a superclass or is assigned to a specific superclass by the option IN, the class method does not need to be implemented within this class. Instead, an object of this class executes the corresponding method in the superclass. When the class method <MethodName> is implemented in a superclass, it is automatically available for use in a subclass. When a class method of the same name is also declared in the subclass, the object executes the class method within the subclass and not the class method of the same name which exists in a superclass.
Within the source code for the class method the class object is always available via the variable self. This occurs whether the message to call the class method was sent to an instance object or directly to the class object.
When using CLASS METHOD outside the class declaration to preface the method implementation, the name of the class method <MethodName> is always used. When the method is declared as <MessageName> IS <MethodName> , <MessageName> determines the message which must be sent to an object, for the method <MethodName> to be executed.
<MessageName> is a mechanism for providing an alternative name for a class method. It can be used to declare a different name in this class than that used in the superclass. This is especially useful when two or more superclasses contain class methods with the same name. When this occurs, declaring alternative message names (unique within this class) for calling the class method in each of the superclasses is recommended. This clearly indicates which superclass class method will be used. To accomplish this, the declaration is used in the form CLASS METHOD..IS..IN.
The visibility of a class method is determined by the visibility attribute, which is set with one of the keywords EXPORTED:, PROTECTED:, or HIDDEN: (see the sections covering each attribute for additional information).
In general, class methods are only needed for accessing class variables. Class variables are member variables of the class object, and exist only once within a class. The value or contents of a class variable is the same for all instances of a class.
Reserved names: The object model of Xbase++ uses the following identifiers for class methods which are reserved and cannot be used in naming class methods. These are:
|Returns name of class
|Returns class object
|Determines whether or not an object is derived from a particular class :isDerivedFrom(<cClassName> | <oClassObject>) --> .T.|.F.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.