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

Why Inheritance Can Be Problematic

Understand the fragile base class problem and tight coupling issues that arise from deep inheritance hierarchies.

Why Inheritance Can Be Problematic

You'll learn why deep inheritance hierarchies create fragile, tightly-coupled code that's hard to maintain.

The Fragile Base Class Problem

Imagine building a tower of blocks where every level depends on the one below. If you modify a bottom block, everything above shakes or collapses. That's inheritance.

When you extend a class, the child class tightly couples to its parent's implementation details—not just its public interface. Change something in the base (parent) class, and you risk breaking every class that inherits from it.

class Animal {
  move() {
    return "walking";
  }
}

class Dog extends Animal {
  move() {
    return super.move() + " on four legs";
  }
}

// Later, you change Animal's move method
class Animal {
  move() {
    return { type: "walking", speed: 5 }; // Now returns an object!
  }
}

// Dog.move() breaks — it tries to concatenate strings with an object

Deep Hierarchies Amplify the Problem

The more layers you add, the more fragile the system becomes. A change at the top ripples down through every descendant. You can't see all the places your changes might break without examining every child class.

Tight Coupling Makes Changes Expensive

Inheritance creates "is-a" relationships that are hard to undo. Once Dog extends Animal, you're locked in. Changing what Animal does forces you to audit and potentially rewrite Dog, Cat, Bird, and every other descendant.

This is why composition (mixins, factories) often wins: you can swap behaviors without rewriting entire hierarchies.

Key Takeaway: Inheritance creates fragile, tightly-coupled code where changes to base classes cascade unpredictably through child classes—favor shallow hierarchies or composition instead.