Composition vs inheritance: a product catalogue

Build values from small, swappable parts instead of a chain of embedded structs.

Level Beginner

What you will see

  1. Many kinds of products
  2. A family tree made of embedded structs
  3. One new idea, twice the types
  4. A product made of parts
  5. Asking the parts
  6. When embedding is the right choice

Before / after

Base: composition-over-inheritance-base-goView the diff

Exercises