Try OpenEdge Now
skip to main content
Object-oriented Programming
Object-oriented Programming and ABL : Overview of object-oriented programming : Delegation
 

Delegation

Delegation uses composition to build a class from one or more other classes without relating the classes in a hierarchy. In many cases, one class needs to invoke behavior in another class that is not part of its class hierarchy. A class does this by maintaining a reference to the other class and invoking the other class’s public methods or accessing its public data members or properties. When a class references another class this way, it is a container class for the other class that it accesses as a delegate. Thus, delegation is a relationship between classes where one class forwards a message it cannot otherwise handle to another class (its delegate).
Because the container class delegates behavior to a separate delegate class, the behavior is not automatically accessible from outside the container class. Unlike an inheritance relationship, delegation requires the container class to define a stub for the message in the form of a method to allow other classes to access the behavior of the delegate. Thus, the stub method in the container class is a method that is typically of the same name as the effective method in the delegate. Because a delegation relationship is established entirely by reference to the delegate, delegation offers the flexibility to easily change the referenced delegate at run time without any required change to the container. This there by provides an instance of the container class with a form of dynamic inheritance.
You can create your own container and delegate classes in ABL. You can also use interfaces to help enforce consistency between the method stubs implemented in a given container class and the effective method implementations defined in a corresponding delegate class.
* Comparison with procedure-based programming