Favor object composition over class inheritance

“Design Patterns: Elements of Reusable Object-Oriented Software”

Composition over inheritance (or composite reuse principle) in object-oriented programming (OOP) is the principle that classes should achieve polymorphic behavior and code reuse by their composition (by containing instances of other classes that implement the desired functionality) rather than inheritance from a base or parent class. Wikipedia

It means that code reuse should be achieved by assembling smaller unit of functionality into new objects instead from classes and creating object taxonomies.

In other words, use can-do, has-a, or uses-a relationships instead of is-a relationships.

Diffrences beween composition and class inheritance: The purpose of composition: make whole out of parts. The purpose of inheritance: It have semantic(meaning) with which it arange concepts from generalized to specialized, grupping releates concepts in subtrees. Capture mehanics, behavior(methods) of class and making it available for reuse and augumentationi.