Try OpenEdge Now
skip to main content
Object-oriented Programming
Getting Started with Classes, Interfaces, and Objects : Using the CLASS construct : Defining properties within a class
 

Defining properties within a class

You can define certain types of data for a class as properties. Properties are always class members and must be defined in the main block of the class. The data types for properties are restricted to those that you can specify as the return type of a method. You must define all other types of class data as data members or class-scoped handle-based objects. For more information, see Defining data members within a class and Defining class-scoped handle-based objects.
Unlike data members, the DEFINE statement for defining properties provides a built-in mechanism for encapsulating data using special methods called accessors. The accessors you define determine if a given property can be read, written, or both. Accessors can also directly access four general categories of data:
1. Default memory for the property that has the same data type as the property definition
2. Any other accessible data members of the class hierarchy where the property is defined
3. Any PUBLIC data that is available from other classes, as appropriate
4. Any internal data defined within the accessors themselves
Depending on how you implement these accessors, when you access the property, you can directly access the property’s default memory, or you can indirectly access and process other data elements of various types that are available to the accessors. Thus, property accessors can encapsulate state and behavior similar to a method. No matter how you implement a property’s accessors, you can access a property in exactly the same way as you access an equivalently defined variable data member.
Although a property accessor can access data of any type, the data that a property accesses is typically defined with the same data type as the property itself, which is the most common and effective use of a property definition. To effectively encapsulate types of data that you cannot define explicitly as a property data type, like temp-tables, you can define named methods with interfaces designed to handle these data types. For more information on defining methods, see Definingmethods within a class.
By default, a property is an instance member that is defined for access, according to its access mode, only within or through the instance of the class in which it is defined. A property can also be defined as static, which associates the property with the class type (not an instance) and makes it available, according to its access mode, throughout the ABL session without the need for a class instance. For more information on accessing static properties, see Accessingstatic members.
You can also define an abstract property prototype in an abstract class type definition, and you can define an interface property prototype in an interface type definition. A property prototype defines its data type and certain other options, but no implementation. Both types of property prototype define a property that must be implemented appropriately in the class hierarchy where it is defined. For more information on defining interface property prototypes, see Defininginterfaces and Usingthe INTERFACE construct.
* DEFINE PROPERTY statement
* Comparison with procedure-based programming