I'll Be Backend
Principles

Composition over Inheritance: End the Subclass Explosion

Composition over inheritance means an object holds other objects as fields and asks them for their part of the work, instead of getting that work from a parent class. When a class varies in two independent ways, inheritance needs one subclass for every pair. These lessons take a car rental desk with a subclass per car kind and cover, move car and cover into fields, and then add vans as one small class.

Pick your language

When to use it

Use it when

A class varies in two or more independent ways, like car kind and cover.

Skip it when

There is only one way to vary. Nothing multiplies, so a delegate only adds an object and a call.

Spot it by

Class names that join words from two lists, like InsuredSuv, and the same override copied across siblings.