Statement CLASS Foundation
[STATIC|FREEZE|FINAL] CLASS <ClassName> ;
[FROM <SuperClass,...>] ;
[CLASS METHOD initClass]
[ METHOD init]
<class declaration statements>
The statement CLASS starts the declaration of a class. Following the class definition are the declarations of the member variables and methods which are available to instances of the class. The class declaration ends with the statement ENDCLASS. Following the declaration section, the methods declared in the class must be coded. (See: METHOD (Implementation)).
The class declaration CLASS...ENDCLASS consists entirely of four parts:
The class function has the function name <ClassName> and returns a reference to the class object. The class object represents the class and using the class method :new(), generates instances (objects) of the class. The word "new" is reserved and cannot be used as the name of a method or an instance variable. Other reserved identifiers used for methods in all classes are listed in the table below:
|Returns the class name as a character string
|Returns the class object of an instance
|Determines whether or not an object is derived from a particular class :isDerivedFrom(<cClassName> | <oClassObject>) --> .T.|.F.
|Creates instances of a class
When the class declaration uses the optional statement STATIC CLASS, the class function is a STATIC FUNCTION and cannot be called outside the source code file within which the class is declared.
A class may be produced from previously declared classes. The names of the declared classes must be indicated by the statement CLASS with the option FROM as a comma separated list <SuperClass,...>. These classes are superclasses, and the new class is a subclass of the superclasses. All classes that are not declared as STATIC, may be used as superclasses, including classes contained in the Xbase++ language. The new class <ClassName> inherits the entire structure of the superclasses. In this way, the new class has access to all member variables and methods of the superclasses which are not declared with the HIDDEN: visibility attribute within the superclasses.
The option FROM defines all classes whose member variables and methods are to be inherited by the new class. If class variables exist in the superclasses, all the class variables of the superclasses which are not declared SHARED are added to the class <ClassName>. When SHARED is not used, the new class receives its own class variables with the same names as those in the superclasses. In this case the new class cannot access the same class variables as the superclasses. The new class has, effectively, received copies of the class variables of the superclasses and accesses its own values.
The option SHARING is significant only when the new class <ClassName> inherits from two or more classes <SuperClass,...> which themselves have a common superclass. The following example should help explain this relationship: Assume a class A with an instance variable iVarA. Classes B and C are subclasses of class A (and thus each include a copy of iVarA). Finally a class D is declared which is derived from classes B and C. When the SHARING option is used in the class D declaration, both of the inherited copies of the instance variable iVarA in classB and C are brought together as a single instance variable in class D. Class D then has only one copy of instance variable iVarA.
The following statements (<class declaration statements>) are used in declaring member variables and methods:
|Only visible within methods of this class
|Only visible within methods of this class and its subclasses
|Visible to the entire application (globally visible)
|Declaration of a class variable
|Declaration of an instance variable
|Declaration of a class method
|Declaration of an instance method
By default, all of the instance variables and methods declared in the class are treated as having HIDDEN: visibility. When a member variable or method is HIDDEN:, it is not visible outside the methods of the class. When the visibility attribute PROTECTED: or EXPORTED: is used, all subsequent member variables and methods declared assume this visibility until a different visibility attribute is used. In addition to the keywords affecting visibility, member variables can assume separate attributes that control the ability to assign values (write access). More information on visibility may be found in the sections discussing the respective attributes.
Details for the declaration of member variables and methods are found in the sections covering the corresponding statements.
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.