Calling methods from inside a class hierarchy where they are defined
You can directly access methods from within the class hierarchy where they are defined by invoking the method name. This includes all methods implemented directly within the class definition and all PUBLIC and PROTECTED methods implemented in any super class of the class hierarchy. Invoking an overridden method from within a class hierarchy executes the method defined in the most derived subclass of a given class hierarchy. This is true even if the method is called from a super class that contains an overridden implementation. Thus, for an instance method, the actual implementation of a method invoked from within its own class definition depends on where that class definition resides in the class hierarchy of a given class instance.
You can also use additional ABL elements to access instance methods within the hierarchy that have the following characteristics:
The method is defined, and possibly overridden, in one or more super classes. By default (as noted above), invoking the method always invokes the most-derived method in the class hierarchy. However, you can, instead, invoke the closest implementation in a super class of the current class definition by using the SUPER system reference.
The method has the same name as a reserved keyword. By default, ABL does not allow you to invoke a method with such a name directly within the class hierarchy where it is defined, but you can invoke the method using the THIS-OBJECT system reference. You can also use THIS-OBJECT to improve code readability for an internal hierarchy method call.
This is the syntax to invoke a method from inside a class:
Element descriptions for this syntax diagram follow:
[ SUPER ]
A system reference that allows you to call the closest overridden implementation of an instance method specified by method-name and an equivalent signature in the current class hierarchy. For more information, see SUPERsystem reference.
[ THIS-OBJECT ]
A system reference that allows you to call an instance method defined in the current class hierarchy when method-name is a reserved keyword. This system reference can also provide an aid to coding. For more information, see THIS-OBJECTsystem reference.
data-element
If the method returns a value that is assigned, the name of a variable, property, or other data element defined to hold any return value.
method-name
The name of an accessible method in the class hierarchy.
[parameter[ , parameter]...]
The parameters, if any, of the method. For more information on the syntax of parameter, see the Parameter passing syntax reference entry in OpenEdge Development: ABL Reference.
[ NO-ERROR ]
Optionally redirects error processing when the method is called as a statement.
The following is an example from the sample class, acme.myObjs.CustObj, where MessageHandler( ) is an abstract method defined in and inherited from the abstract class, acme.myObjs.Common.CommonObj, and implemented in CustObj:
USING acme.myObjs.Common.*.
CLASS acme.myObjs.Common.CommonObj ABSTRACT:
DEFINE PUBLIC VARIABLE timestamp AS DATETIME NO-UNDO.
METHOD PUBLIC VOID updateTimestamp( ):
timestamp = NOW.
END METHOD.
METHOD PROTECTED ABSTRACT CLASS MsgObj MessageHandler (INPUT piObjType AS CHARACTER).
END CLASS.
The constructor in CustObj invokes the PROTECTED method MessageHandler( ) within its class hierarchy by directly calling the method by its name:
USING acme.myObjs.*.
USING acme.myObjs.Common.*.
USING acme.myObjs.Interfaces.*.
CLASS acme.myObjs.CustObj INHERITS CommonObj
IMPLEMENTS IBusObj:
...
DEFINE PRIVATE VARIABLE rMsg AS CLASS MsgObj NO-UNDO.
...
CONSTRUCTOR PUBLIC CustObj( ):
... rMsg = MessageHandler("acme.myObjs.CustObj"). END CONSTRUCTOR.
METHOD PROTECTED OVERRIDE CLASS MsgObj MessageHandler (INPUT piObjType AS CHARACTER): RETURN NEW MsgObj (piObjType).
END METHOD.