Hasty Briefsbeta

When did people favor composition over inheritance?

16 days ago
  • #object-oriented programming
  • #software design
  • #design patterns
  • The phrase 'favor composition over inheritance' originates from the 'Design Patterns' book by the Gang of Four.
  • Inheritance is described as 'white box' reuse due to visibility of implementation details, while composition is 'black box' reuse.
  • Modern languages like Java allow control over what subclasses can view or change, mitigating some inheritance issues.
  • Composition is more flexible at runtime but requires more manual effort compared to inheritance.
  • Barbara Liskov's principle emphasizes semantic behavior in subtyping, suggesting composition can be more liberating for designers.
  • The aphorism overlooks alternatives like first-class procedures (e.g., lambdas) which might be preferable in some cases.