Composition trumps multiple inheritance in terms of flexibility. As with the Adapter Pattern (see the GOF book), it clearly allows us to adapt (morph) classes to different behaviors depending on callers request. See the IAdaptable
interface in Eclipse RCP. Basically using interfaces is the same as using the Adapter Pattern built in in the Java language directly. But using adaptable classes is better than implementing multiple interfaces. Adaptable classes are more flexible, but they have some CPU overhead: the instanceof
operator consumes less CPU than calling canAdapt(Class clazz). But in modern JVMs this could be false, since calculating instanceof
with interfaces is more complex than calculating instanceof with inheritance.