Define static members
- Last Updated: October 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
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, PACKAGE-PRIVATE , PROTECTED, PACKAGE-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 Use 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
SUPERorTHIS-OBJECTsystem 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 toTHIS-OBJECT.
- 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:
|
Of course, you would likely revise some of the related sample classes accordingly. For more information on the sample classes see Compare 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 ABL Reference.