Try OpenEdge Now
skip to main content
Object-oriented Programming
Designing Objects: Inheritance, Polymorphism, and Delegation : Class hierarchies and inheritance : Event scoping within a class hierarchy
 

Event scoping within a class hierarchy

A class can subscribe handlers for all of the PUBLIC and PROTECTED events of its super class as well as for any events that it defines. A super class that, in turn, inherits from another class inherits all its super class's PUBLIC and PROTECTED events and so on up to the root of the hierarchy. Therefore when a class inherits all of the PUBLIC and PROTECTED events of its super class, it inherits all of the PUBLIC and PROTECTED events available all the way to the top of the class hierarchy.
While a subclass can subscribe handlers for the PUBLIC and PROTECTED events of any of its super classes, the reverse is not true for instance events. You cannot subscribe handlers to instance events within a class that are defined only by a derived class. Events first defined in a subclass are simply not visible to any of its super classes, even though the subclass exists in the same class hierarchy for a given object as its super classes.
Likewise, events defined as PRIVATE in a super class are not accessible to its derived classes. Because the default access mode for events is PUBLIC, an event is always accessible to a derived class for subscription unless you specifically define it as PRIVATE. Therefore, a key benefit of classes is the PROTECTED access mode, which allows you to subscribe handlers for all protected events within a class hierarchy, but which are invisible for handler subscription by any procedures or other classes that are outside the class hierarchy.
Note that an instance can subscribe an event handler to a PRIVATE event of another instance if both instances are from the same class, and an instance can subscribe an event handler to a PROTECTED event from a second instance if the first instance is in the same class as the second instance or from a subclass of the second instance.
* Comparison with procedure-based programming