Object-Orientation AbusersMedium

Alternative Classes with Different Interfaces: What It Costs and How to Fix It

Two or more classes that perform similar functions but have incompatible method names and signatures.

Annual Cost$1.8k - $14k
Severity
3/5
CategoryObject-Orientation Abusers
Detection4 tools

What It Is

This smell occurs when two or more classes do essentially the same thing but expose different interfaces. For example, one notification class uses send(message, recipient) while another uses dispatch(payload, target). Callers cannot use them interchangeably, so switching between implementations requires rewriting all call sites. The classes should implement a common interface, but because they were written independently (often by different developers or at different times), they diverged in naming and structure.

Threshold: When two classes have 3+ methods that do the same thing with different names, extract a shared interface. When you find yourself writing adapters between similar classes, the smell is confirmed.

Why It Costs Money

1

Switching implementations requires rewriting call sites. When you decide to replace one email sender with another, every caller must change because the method names and parameter structures differ.

2

Code that should be generic must be duplicated. You cannot write a single function that works with both classes, so you write adapter code or duplicate logic.

3

Testing doubles are inconsistent. Mocks for one implementation do not work for the other, doubling test maintenance.

Specific Cost Mechanisms

  • Implementation switching: rewriting call sites costs 4-12 hours per switch instead of near-zero with a shared interface
  • Adapter proliferation: wrapper classes that translate between interfaces add complexity and maintenance cost
  • Duplicate test infrastructure: separate mocks and test setups for functionally identical classes

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,800$4,200$8,400
5 devs$3,000$7,000$14,000
10 devs$4,500$10,500$14,000
20 devs$6,000$14,000$14,000

How to Detect It

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

SonarQube
squid:S1214

Interface segregation violations (indirect)

CodeClimate
similar-code

Detects structurally similar classes with different names

PMD
LooseCoupling

Flags concrete type references that should use interfaces

IntelliJ IDEA
Extract interface suggestion

Suggests shared interfaces when similar classes are detected

Refactoring Patterns

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

Extract Superclass/Interface

Two classes have overlapping behaviour that should be unified

Effort: 2-4 hours
Impact: Enables polymorphic usage and eliminates adapter code

Rename Method

Classes do the same thing but use different names

Effort: 30-60 minutes per method
Impact: Aligns interfaces for future extraction

Move Method

Behaviour in one class belongs in the other

Effort: 1-3 hours
Impact: Consolidates duplicated behaviour

Related Smells