Skip to content

Latest commit

 

History

History
9 lines (6 loc) · 402 Bytes

36-composition-over-inheritance.md

File metadata and controls

9 lines (6 loc) · 402 Bytes

Item 36: Prefer composition over inheritance

When all we need is a simple code extraction or reuse, inheritance should be used with caution; instead, we should prefer a lighter alternative: class composition.

Important downsides of this approach:

  • We can only extend one class.
  • When we extend, we take everything from a class
  • Using superclass functionality is much less explicit.