Alternative Classes with Different Interfaces

Referenced by patterns
Compare
Symptom
Human

Two classes do similar things but with mismatched method names and signatures — sortBy() vs orderUsing(), valueOf() vs evaluate().

Agent

Two classes the agent recognizes as doing similar things but with mismatched method names and signatures; the agent must learn both vocabularies and translate between them.

Goal
Human

Equivalent operations have equivalent signatures; a shared superclass or interface emerges naturally.

Agent

Equivalent operations have equivalent signatures; the agent uses one mental model and the type system enforces substitutability.

Smellier version

class CSVExporter { writeAll(rows) {} }
class JSONExporter { dump(data) {} }

Fresher version

class CSVExporter implements Exporter { write(rows) {} }
class JSONExporter implements Exporter { write(rows) {} }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Substitution becomes copy-paste; consumers can't treat the two interchangeably; abstraction over them is impossible.

Agent

Substitution becomes copy-paste; abstraction over the two is impossible; the agent must hold both interfaces in working memory to use either.

Tradeoff
Human

Aligning the interfaces may force renames across both classes and every consumer; for classes that have stable independent APIs and only superficial similarity, the alignment is invented coherence.

Agent

Aligning the interfaces forces renames across both classes and every consumer; the agent verifying the alignment must update every call site and confirm the new common contract holds for both.

Relief
Human

Polymorphic use becomes possible; new alternatives plug in without bespoke adapters.

Agent

A shared interface lets the agent dispatch through one type signature instead of loading both class surfaces; new alternatives plug into the interface, and consumer code generalizes across them without per-class branching.

Trap
Human

Forcing two classes into a shared interface because they look similar — even when their underlying contracts genuinely differ — creates an abstraction that hides important distinctions.

Agent

Forcing two classes into a shared interface despite genuinely different contracts produces an abstraction the agent must constantly special-case — important distinctions hide behind a fake polymorphism.