Composition vs inheritance: a product catalogue
Build objects from small, swappable parts with a factory function instead of a tree of subclasses.
Level Beginner
What you will see
- Many kinds of products
- A family tree of products
- One new idea, twice the classes
- A product made of parts
- Asking the parts
- When inheritance is the right choice
Before / after
Base: composition-over-inheritance-base-jsView the diff