Course contentsShow
← JavaScript
Lesson 1852 of 2,72338. Object-Oriented PatternsFree lesson

Inheritance Hierarchies That Are Too Deep

Understand why deep class hierarchies become brittle and hard to reason about.

Inheritance Hierarchies That Are Too Deep

You'll learn why stacking inheritance levels creates fragile, confusing code.

The Tower That Falls

Imagine building a tower of blocks where each level depends on everything below it. The taller it gets, the more unstable it becomes—and if you need to change a block near the bottom, the whole tower might collapse.

Deep inheritance hierarchies work the same way. When you create a chain like Animal → Mammal → Carnivore → Feline → HouseCat → SiameseCat, you're building fragility into your design.

Why Deep Hierarchies Are Brittle

Each level in the chain:

  • Locks you into assumptions made by all parent classes
  • Makes changes risky because modifying a parent affects all descendants
  • Obscures behavior since you must trace through multiple classes to understand what a method does
  • Creates tight coupling where children can't exist without their entire ancestry

When SiameseCat calls a method, you might need to look through six different classes to find where it's defined or overridden. This violates the principle that code should be easy to reason about.

The Reasoning Problem

The deeper the hierarchy, the harder it becomes to answer simple questions:

  • Where does this method come from?
  • What will super call?
  • If I change this parent class, what breaks?
  • Why does this subclass behave differently than expected?

Each level adds cognitive load. Most experts recommend keeping inheritance to 2-3 levels maximum, preferring composition (as you've learned with mixins and factories) for adding behavior.

Key Takeaway: Deep inheritance hierarchies become brittle and confusing; favor shallow hierarchies (2-3 levels max) and composition over creating tall inheritance towers.