Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Instantiating and managing class-based objects : Defining an object reference variable or property
 

Defining an object reference variable or property

This is the syntax to define an object reference variable:

Syntax

DEFINE [access-mode ] VARIABLE object-reference
  AS [ CLASS ]object-type-name[ EXTENT constant ][ NO-UNDO ] .
This is the syntax to define an object reference property:
DEFINE [access-mode ] PROPERTY object-reference
  AS [ CLASS ]object-type-name[ EXTENT constant ][ NO-UNDO ]
accessor-definitions .
Element descriptions for this syntax diagram follow:
Note: For more information on each option, see the specified references in this book and also the DEFINE VARIABLE and DEFINE PROPERTY statement reference entries in OpenEdge Development: ABL Reference. For variables, no other options apply, because they are not supported for object references.
access-mode
The optional access mode specifies where and how the variable or property can be accessed, and the available options depend on where the variable is defined (as a class data member or property, within a procedure, etc.). For more information on accessing class data members and properties, see Accessing data members and properties.
object-reference
The name of a variable or property that will hold an object reference value.
CLASS
The CLASS keyword is required if object-type-name conflicts with an abbreviation for a built in ABL data type, such as INTE (INTEGER). Otherwise, it can optionally be used to clarify the readability of the statement.
object-type-name
The type name of a class or interface. This can be the fully qualified object type name or the unqualified class or interface name, depending on the presence of an appropriate USING statement in the class or procedure file. For more information on object type names, see Defining and referencing object type names. For more information on the USING statement, see Referencing an object type name without its package.
EXTENT constant
An object type name defined with an extent is an array of object references to that type. In other words, each element of the array can contain an object reference to an instance of the specified type. If constant is zero, then the object reference is not an array.
NO-UNDO
If specified, prevents the variable or property value from being undone if a transaction that changes it is rolled back.
accessor-definitions
One or two property accessors that indicate if the property is readable, writable, or both.
For more information on defining:
*Variables as data members, see Defining data members within a class
*Properties, see Definingproperties within a class
The following example shows a fragment of the Main class from the sample classes that are fully implemented in Sample classes. This fragment defines several private variables to hold object references and filenames:
USING acme.myObjs.*.
USING acme.myObjs.Common.*.
USING acme.myObjs.Interfaces.*.

CLASS Main:
  DEFINE PRIVATE VARIABLE cOutFile AS CHARACTER NO-UNDO.
  DEFINE PRIVATE VARIABLE rCommonObj AS CLASS CommonObj NO-UNDO.
  DEFINE PRIVATE VARIABLE rCustObj AS CLASS CustObj NO-UNDO.
  DEFINE PRIVATE VARIABLE rCustObj2 AS CLASS CustObj NO-UNDO.
  DEFINE PRIVATE VARIABLE rHelperClass AS CLASS HelperClass NO-UNDO.
  DEFINE PRIVATE VARIABLE rIBusObj AS CLASS IBusObj NO-UNDO.

  CONSTRUCTOR PUBLIC Main ( ):
    ASSIGN
      /* Create an instance of the HelperClass class */
      rHelperClass = NEW HelperClass ( )

      /* Create an instance of the CustObj class */
      rCustObj     = NEW CustObj ( )
      cOutFile      = "Customers.out".

    /* Subscribe OutputGenerated event handler for CustObj */
    rCustObj:OutputGenerated:Subscribe(OutputGenerated_CustObjHandler).
  END CONSTRUCTOR.
  ...
END CLASS.