# 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.

![Cheat sheet: Prefer Composition to Inheritance](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/59b2508ec0e2470c8f540545ebb1921a.webp)

- Category: Data Structures
- Level: Apprentice
- Tags: Class Explosion, Composition, Composition over Inheritance, inheritance, OOP, software-development
- Author: Gregor Dzierzon
- Updated: November 17, 2026

Source: https://www.ask-codey.com/cheat-sheets/dp-prefer-composition-cheat-sheet
