Two classes or interfaces with substantial shared structure — `Employee` and `Department` both carrying `name`, `id`, and similar id-management methods.
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; }
Bug fixes must land in both; future shared behavior has no obvious home; the relationship between the types is invisible to readers.
Inheritance is inflexible — if the duplication is shallow, prefer Extract Class (composition) over Extract Superclass.
Bug fixes and new shared behavior land in one place; the relationship between the types is documented in code.
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.