Extract Superclass

Referenced by patterns
Symptom

Two classes or interfaces with substantial shared structure (fields, methods); the agent verifying changes must update both consistently.

Goal

Shared structure lives on the parent with one declaration; queries about either subclass load the parent's contract once instead of paying the cost of loading N near-identical subclass declarations.

Before the refactoring

class Employee { name; id; salary; }
class Department { name; id; budget; }

After the refactoring

class Party { name; id; }
class Employee extends Party { salary; }
class Department extends Party { budget; }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

Bug fixes must land in both types; the agent's reasoning about shared invariants must verify they hold identically across both.

Tradeoff

Inheritance is inflexible; for shallow duplication, the agent's downstream changes are constrained by the parent in ways composition (Extract Class) would have avoided.

Relief

Shared behavior lives on the parent with one definition; edits to the shared method land once and propagate to every subclass through inheritance, removing the N-copy synchronization cost.

Trap

Extracting superclasses for shallow duplication locks the agent into inheritance constraints when composition would have left both classes free to diverge.