next up previous
Next: 2.3.2 Illustrative Examples Up: 2.3.1 General scheme Previous: 2.3.1.2 Overriding.

2.3.1.3 Conflict resolution

If several (base) classes define methods that share the same signature, the translation sketched in this section permits just one method with that signature in the child class. This is a problem if the different base class methods have different semantics and child class instances are substitutable for base class instances: then a wrong method that happens to share the name and signature can be invoked. This problem is illustrated in [30, page 273-275] with the following example (adapted here to pseudo-Java syntax):


4#4
In such a case we need two methods in the LotterySimulation class, say drawLottery() and drawGraphical(). Without language support for multiple inheritance, however, dynamic binding does not know that it should select the drawLottery() method for an invocation of draw() on a variable of type Lottery and the drawGraphical() method for an invocation of draw() on a variable of type GraphicalObject.

Implementation of such context-dependent behavior without language support results in convoluted, impractical designs. This is problematic because it leaves us only with the choice to give up substitutability of a child class instance for a parent class instance (by not declaring the implements relation). As a consequence, child classes cannot override methods in the respective parent classes because the simulation of overriding depends on substitutability of child instances for parent class instances.


5#5

An example showing that much better results can be achieved with suitable language support is shown in Section [*].


next up previous
Next: 2.3.2 Illustrative Examples Up: 2.3.1 General scheme Previous: 2.3.1.2 Overriding.
T. K. Prasad