Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Using static members of a class : Defining static members
 

Defining static members

You can define many kinds of class members as static, including, a single optional constructor, with an empty parameter list. In addition, you can define any number of the following static class members that support the PRIVATE, PROTECTED, and PUBLIC access modes:
*Variable data members
*Methods
*Properties
*Events
You can define any number of the following static data members that support only the PRIVATE and PROTECTED access modes:
*Buffers
*ProDataSets
*Data-sources
*Queries
*Temp-tables
You can, and typically do, define both static and instance members in the same class. In other words, ABL does not support the concept of a static class where all of its members must be static. Syntactically, you can define a static member of a class exactly the same as an instance member, except for the addition of the STATIC option in the member definition. For more information on the syntax for defining static members, see Using the CLASS construct.
Basic requirements for defining static members include the following:
*As part of its definition, a static member can access only other static members and other data that is defined locally as part of the static member definition itself. A static member cannot access an instance member from within the same class hierarchy as the static member, itself. As a result, you cannot use the SUPER or THIS-OBJECT system references from within a static method, property accessor, or constructor. However, you can access public instance members on an object reference to any class instance that is not equal to THIS-OBJECT.
Note: When accessed from a class, ABL views the default buffer of a database table as an instance member of the class. Note also, that, unlike a static member, an instance member can include access, in its definition, to both other instance members and to static members.
*A complex static data member, such as a ProDataSet, can only include another static data member in its definition (in this case, a buffer) that has the same or a less restrictive access mode as the access mode defined for the complex data member itself.
For example, in the sample acme.myObjs.Common.CommonObj class, you might change the definitions of the timestamp instance variable and updateTimestamp( ) instance method to a static property and method, respectively, as follows:
USING acme.myObjs.Common.*.

CLASS acme.myObjs.Common.CommonObj ABSTRACT:
  DEFINE PROTECTED STATIC PROPERTY dtTimestamp AS DATETIME NO-UNDO
    GET .
    PRIVATE SET .

  METHOD PUBLIC STATIC VOID updateTimestamp ( ):
    CommonObj:dtTimestamp = NOW.
    RETURN CommonObj:dtTimestamp.
  END METHOD.
  ...
END CLASS.
Of course, you would likely revise some of the related sample classes accordingly. For more information on the sample classes see Comparing constructs in classes and procedures.
For more examples of static definitions for all supported class members, see the examples provided with the CLASS statement reference entry in OpenEdge Development: ABL Reference.
* Defining a static constructor
* Defining static method overrides and overloadings