next up previous
Next: 2.3.1.3 Conflict resolution Up: 2.3.1 General scheme Previous: 2.3.1.1 Simple forwarding.

2.3.1.2 Overriding.

However, achieving the effect of overriding is also possible on the basis of aggregation and forwarding, provided that the parent classes are available for modification [20,8]. The essential idea is to give the parent object a back-reference to the object that initially forwarded the message. Messages otherwise sent to this by the parent are now sent via the back-reference, enabling execution of overriding methods from the child.

The back-reference can either be stored in the parent object or it can be passed dynamically as an additional argument of forwarded messages. The first approach is called the stored pointer model, the second one is called the passed pointer model [8]. Applying the passed pointer model to our example yields:


3#3
Now invocations of method a() and b() on an instance of class C both return the string "C". Note that we had to add the method b1() to interface IB and relax the visibility status of method b1() from protected to public, thus generally exposing details that should be known only to subclasses / child classes. This translation cannot be substantially improved using Java 1.1 features such as nested classes, reflection, etc. A detailed discussion and usability evaluation of the passed pointer model and the stored pointer model can be found in [20].


next up previous
Next: 2.3.1.3 Conflict resolution Up: 2.3.1 General scheme Previous: 2.3.1.1 Simple forwarding.
T. K. Prasad