Remove Subclass

Compare
Symptom
Human

Empty subclasses that exist only to encode a type code — `class Female extends Person {}` and `class Male extends Person {}` with no overridden behavior.

Agent

Empty subclasses that encode a type code without behavior; the agent navigating the hierarchy traverses indirection for what could be a field.

Goal
Human

A subclass whose only purpose was to encode a type code or add nothing collapses back into a field on the parent.

Agent

The variant becomes a field on the parent; the agent reads variants as data instead of navigating a hierarchy.

Before the refactoring

class Person {}
class Female extends Person {}
class Male extends Person {}

After the refactoring

class Person {
constructor(gender) { this.gender = gender; }
}
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Every new variant is a new file; the hierarchy adds ceremony without behavior; consumers may type-test the subclass instead of treating it as data.

Agent

Every new variant is a new file the agent must create; the hierarchy ceremony costs reasoning without behavior payoff.

Tradeoff
Human

Removing a subclass referenced by name elsewhere (factories, registries) breaks those references — confirm no consumer is type-testing the subclass.

Agent

If the subclass is referenced by name elsewhere (factories, registries, type-tests), removing it silently breaks those references the agent must find and update.

Relief
Human

Smaller hierarchy; new variants are field values instead of new files; the parent regains its variability point as data.

Agent

Smaller hierarchy; new variants are field values not new files; the agent reasons about variability as data.

Trap
Human

Removing subclasses referenced by name elsewhere — factories, registries, type-tests in legacy code — breaks those references silently.

Agent

Removing subclasses referenced by factories, registries, or type-tests breaks those references — the agent must find every such consumer before deletion.