Composition over inheritance
Composition over inheritance is a design principle that favors assembling objects from components instead of deriving classes through inheritance hierarchies.
Data-Oriented Programming: Reduce software complexity
Composition over inheritance is a design principle that favors assembling objects from component objects instead of extending classes through inheritance.
- How it is used
- Uses composition to avoid escalating complexity when a system gains overlapping member capabilities.
- How deep it goes
- Explains the design warning through class diagrams and diamond ambiguity, but stops short of implementation details.
- Examples
- Uses a library system with ordinary, VIP, and Super members whose overlapping capabilities strain the class diagram.
- What you can do after
- Evaluate whether adding a feature is making inheritance structure dangerously complex, then favor composition as the design direction.
Go in Action, Second Edition
Composition over inheritance is a design pattern that builds complex types by combining simpler components instead of deriving them from superclasses.
- How it is used
- Models domain-specific data and behavior in Go by composing types for a recipe application.
- How deep it goes
- Explains the principle through named types, structs, embedded types, collections, interfaces, and methods, stopping at application-level examples.
- Examples
- Uses measurements, ingredients, recipe steps, scaling, unit conversion, recipe summaries, and grocery-list generation.
- What you can do after
- Build it from scratch by composing Go types and interfaces into extensible domain models with scaling and conversion behavior.
Read how Go in Action, Second Edition explains composition over inheritance →
Related concepts
- inheritancecontrasts with · Inheritance is a mechanism by which a child type or element receives properties, values, or behavior from a parent, subject to system rules and possible overrides.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

