Design Patterns · Junior · Question 34 of 75
What does "composition over inheritance" mean?
- ✓Correct answer: Assemble behavior from parts instead of deep hierarchies
- 2Always use classes instead of functions and objects
- 3Never use
extends- it's forbidden in modern JS
Explanation
Deep inheritance is fragile: a change in the base class breaks subclasses, and behavior gets "locked" into the hierarchy. Composition (functions, hooks, children, strategy objects) is more flexible. React explicitly recommends composition over component inheritance.