Software Engineering ยท Architecture
Building behavior by assembling small, independent objects instead of extending a shared base class, avoiding deep and fragile class hierarchies.
Mental model: Building with swappable Lego pieces instead of a rigid class hierarchy you can't easily unbolt.
Example: A game character built by combining a Movable, a Damageable, and a Renderable component instead of extending one monolithic Character base class.
In practice: Inheritance tightly couples a subclass to its parent's implementation details, so a change deep in the hierarchy can ripple unpredictably; composition keeps that coupling explicit and swappable.
Debated: Not universal โ this advice, popularized to fix inheritance abuse in Java-era OOP, is sometimes applied too dogmatically when a shallow, well-understood inheritance hierarchy is genuinely simpler than a pile of composed objects.