next up previous
Next: 2.3.3 Language support Up: 2.3.2 Illustrative Examples Previous: 2.3.2.4 Marker interfaces.

2.3.2.5 Static versus dynamic composition.

The lack of multiple inheritance does prohibit certain reasonable static combinations of built-in classes in Java. For instance, one cannot define a class of objects that can be used both as a java.io.LineNumberReader and as a java.io.InputStreamReader, or as a java.io.LineNumberReader and as a
[4] java.io.PushbackReader.

Instead, Java just provides constructors to turn any Reader instance into one of LineNumberReader, InputStreamReader or PushbackReader by applying the decorator pattern, as explained in Section [*]. Replacing anticipated, static composition of different abstractions via multiple inheritance by demand-driven, dynamic composition via aggregation is a gain of functionality, not a loss.


T. K. Prasad