next up previous
Next: 2.3.2.1 Code reuse without Up: 2.3 Approximating Multiple Inheritance Previous: 2.3.1.3 Conflict resolution

   
2.3.2 Illustrative Examples

To sum up, multiple inheritance can be simulated by joint use of

The applicability of the latter two techniques is inhibited, however, by the need to provide suitable ``hooks'' in parent classes. Furthermore, conflicting methods in parent classes prevent simulation of polymorphism, even if the parent classes provide the required hooks.

Whereas the above limitions of the available simulation techniques prevent a full simulation of multiple inheritance in cases where it would be useful, there are also other cases where a full simulation is not required and a design without multiple inheritance is preferable. We now present some practical applications of the above translation in Java, which illustrate differents facets of both situations.

On the one hand, the examples review some widely-used combinations of the three simulation techniques discussed above, showing that a rigid implementation of the presented translation is often neither appropriate nor possible. The right choice is driven by the needs of a particular application and constrained by the limitations of available built-in or third-party supplied classes that cannot be modified. On the other hand, they illustrate a number of specialized patterns derived from the above translation. Anticipating the need for customization, vendors can apply such patterns in designing utility classes and frameworks, to facilitate their use in multiple inheritance contexts.



 
next up previous
Next: 2.3.2.1 Code reuse without Up: 2.3 Approximating Multiple Inheritance Previous: 2.3.1.3 Conflict resolution
T. K. Prasad