Referring to the below link:
http://www.javaworld.com/javaworld/jw-11-1998/jw-11-techniques.html?page=2
The composition approach to code reuse pro
Return type of Fruit.peel()
is being changed from int to Peel
. This doesn't meant that the return type of Apple.peel()
is being forced to change to Peel
as well. In case of inheritance, it is forced and any client using Apple
has to be changed. In case of composition, Apple.peel()
still returns an integer, by calling the Peel.getPeelCount()
getter and hence the client need not be changed and hence Apple
's interface is not changed ( or being forced to be changed)