Наследование против композиции [дубликат]

Possible Duplicate:
Prefer composition over inheritance?

Интересно, почему (или в каких случаях) следует рассматривать наследование, а не композицию, когда в нем так много минусов:

if we implement/override a method in a subclass which calls the method of the superclass, there's no guarantee that another version of our superclass (maybe some library) won't break our code if there will appear a new method in the superclass with the same signature that the sublclass method has, but with different return type, our class won't compile.

Поэтому я не могу себе представить, как на Земле мы можем на это положиться. Автор суперкласса может захотеть улучшить производительность, и наш клиентский код может сломаться.

So my questions are:

How are these problems solved (e.g. in standard Java libraries)? When to use inheritance and composition?

Ответы на вопрос(1)

Ваш ответ на вопрос