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

Premature Abstraction and Speculative Generality

Avoid creating abstract classes and interfaces before actual concrete needs emerge.

Premature Abstraction and Speculative Generality

You'll learn why creating abstractions "just in case" leads to bloated, confusing code.

The Trap of Future-Proofing

Premature abstraction happens when you create abstract classes, interfaces, or generalized solutions before you have concrete examples proving you need them. It's like building a multi-story garage before you even own a car — you're solving problems that don't exist yet.

Speculative generality is the habit of adding flexibility "in case we need it later" — extra parameters, configuration options, or extension points that nobody actually uses.

Why It's Harmful

When you abstract too early:

  • Your code becomes harder to understand because readers must decode unnecessary layers
  • You guess wrong about what flexibility you'll actually need
  • Maintenance burden increases — more code to test, document, and update
  • Real requirements get shoehorned into ill-fitting abstractions

Think in Concrete Terms First

// ❌ Premature abstraction — no real need yet
class BaseAnimal {
  constructor(name) { this.name = name; }
  makeSound() { throw new Error('Must implement'); }
}
class Dog extends BaseAnimal {
  makeSound() { return 'Woof'; }
}

// ✅ Start simple with what you actually need
const dog = {
  name: 'Rex',
  makeSound() { return 'Woof'; }
};

Wait until you have at least two or three concrete cases before extracting patterns. Let duplication exist temporarily — it shows you where real patterns emerge.

Key Takeaway: Don't build abstractions for imaginary future needs. Start concrete, and only generalize when actual duplication or variation forces your hand. The best design emerges from real requirements, not speculation.