Skip to content

Composition Over Inheritance

Building complex behavior by combining simple, focused components provides more flexibility than extending through class hierarchies, because composition relationships can vary at runtime while inheritance is fixed at compile time.

Tension Addressed

Inheritance vs. Composition

Recognizable As

Delegation patterns, mixins, traits, dependency injection, decorator pattern, entity-component systems

Canonical Sources

Gang of Four, "Design Patterns" (1994); Joshua Bloch, "Effective Java" (2001); Rich Hickey on simple vs easy

Transfers To

Software Design (patterns), UI Frameworks (component composition), Game Development (entity-component-systems), Microservices (service composition)

Inheritance creates "is-a" relationships that are difficult to change; composition creates "has-a" relationships that can be reconfigured.