Prefer Composition to Inheritance

When every combination of options becomes its own subclass, the classes multiply until a burrito with extra cheese and no onion needs a class of its own; building an item from parts it holds (composition) instead of from a family tree of subclasses (inheritance) turns each new option into one new part.

By

Updated

Cheat sheet: Prefer Composition to Inheritance
Category
Data Structures
Level
Apprentice
Tags
Class Explosion, Composition, Composition over Inheritance, inheritance, OOP, software-development