Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Throughout this chapter, we have discussed the principle of programming to the interface instead of the implementation. The second principle of object-oriented design posited by Gamma, Helm, Johnson and Vlissdes (GoF) is: Favor object composition over class inheritance.
To understand this second key principle, we need to understand exactly what composition means, and its advantages over inheritance. After all, the principle is essentially stating that your programs will be better using composition than inheritance.