Extract Superclass

Referenced by patterns
Symptom

Two classes or interfaces with substantial shared structure — `Employee` and `Department` both carrying `name`, `id`, and similar id-management methods.

Goal

Two types with substantial shared structure get a common parent that owns the shared bits.

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; future shared behavior has no obvious home; the relationship between the types is invisible to readers.

Tradeoff

Inheritance is inflexible — if the duplication is shallow, prefer Extract Class (composition) over Extract Superclass.

Relief

Bug fixes and new shared behavior land in one place; the relationship between the types is documented in code.

Trap

Extracting a superclass for shallow duplication — inheritance is inflexible, and the parent becomes a constraint on future divergence that composition (Extract Class) would have avoided.