CentralNotice From Wikipedia, the free encyclopedia Jump to: navigation , search This diagram shows how the fly and sound behaviour of an animal can be designed in a flexible way by using the composition over inheritance design principle. [ 1 ] Composition over inheritance (or Composite Reuse Principle ) in object-oriented programming is the principle that classes should achieve polymorphic behavior and code reuse by composition (containing other classes that implement the desired functionality), instead of through inheritance (being a subclass). [ 2 ] This is an often-stated principle of OOP, such as in the influential Design Patterns : "Favor 'object composition' over 'class inheritance'." [ 3 ] Some languages, notably Go , use type composition exclusively. 1 Basics 2 Example 2.1 Inheritance 2.2 Composition and interfaces 3 Benefits 4 Drawbacks 5 ...