DispensablesLow

Speculative Generality: What It Costs and How to Fix It

Abstractions, parameters, and classes created for anticipated future needs that never materialised.

Annual Cost$1k - $7k
Severity
2/5
CategoryDispensables
Detection4 tools

What It Is

Speculative Generality occurs when developers create abstractions, interfaces, parameters, or entire class hierarchies 'in case we need them later.' The anticipated use case never arrives, but the abstraction remains, adding complexity that every future developer must understand. Common manifestations include: abstract classes with only one subclass, interfaces implemented by only one class, unused parameters passed through 'for future extensibility,' and factory patterns wrapping a single concrete class.

Threshold: Any abstraction (interface, abstract class, factory) with only one concrete use and no test doubles is speculative. If you have to explain 'we might need this later,' delete it.

Why It Costs Money

1

Every unnecessary abstraction is a concept that developers must understand. When a developer encounters an interface with one implementor, they must figure out whether there is a reason for the interface or whether it is speculative. This investigation wastes 15-30 minutes per encounter.

2

Speculative abstractions make the correct change path unclear. Should the developer modify the interface, the implementation, or add a new implementation? The abstraction suggests that extension is the intended approach, even when modification is simpler.

3

Testing overhead increases. Abstract factories, strategy patterns, and interface hierarchies require more test infrastructure than direct implementations, even when only one variant exists.

Specific Cost Mechanisms

  • Comprehension overhead: 15-30 minutes per developer per speculative abstraction during onboarding
  • Decision paralysis: developers unsure whether to extend or modify the speculative structure
  • Test infrastructure: unnecessary mocks and test doubles for single-implementation interfaces

Estimated Annual Cost

Cost per instance by team size and codebase size. Based on $120,000 average developer salary. See full methodology.

Team SizeSmall (<50k LOC)Medium (50k-200k)Large (200k+)
3 devs$1,000$2,100$4,200
5 devs$1,600$3,500$7,000
10 devs$2,500$5,250$7,000
20 devs$3,200$7,000$7,000

How to Detect It

Specific rules and thresholds for automated detection. See full tool comparison.

SonarQube
squid:S1694 / squid:S1609

Abstract class without abstract methods, functional interface with one use

CodeClimate
method-count / file-lines

Small classes/interfaces with single implementations

PMD
AbstractClassWithoutAbstractMethod / UnusedFormalParameter

Unused abstractions and parameters

IntelliJ IDEA
Class with single implementor

Directly detects single-implementation interfaces

Refactoring Patterns

Proven techniques to eliminate this smell. See all refactoring patterns.

Collapse Hierarchy

An abstract class has only one concrete subclass

Effort: 1-2 hours
Impact: Removes one level of indirection

Inline Class

An interface has only one implementation and no test double

Effort: 30-60 minutes
Impact: Eliminates unnecessary abstraction layer

Remove Parameter

A parameter is passed through but never used

Effort: 15-30 minutes per parameter
Impact: Simplifies method signatures and call sites

Related Smells