Introduce Special Case

Referenced by patterns
Compare
Symptom
Human

The same null-or-special check repeats across multiple consumers — `customer === 'unknown' ? 'occupant' : customer.name` scattered across files.

Agent

The agent finds the same null-or-special check repeating across multiple consumers; consistency depends on every consumer remembering the pattern.

Goal
Human

A repeating null-or-special check becomes a Null Object (or Special Case) that responds sensibly to the same interface.

Agent

The special case responds to the same interface as the real case; the agent reasons without branching at every call site.

Before the refactoring

const name = customer === 'unknown' ? 'occupant' : customer.name;

After the refactoring

const name = customer.name; // UnknownCustomer.name returns 'occupant'
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Every consumer must remember the check; behavior for the special case drifts as consumers diverge; bugs hide where one consumer forgot the check.

Agent

Every consumer is a chance to miss the check; the agent verifying consistency must audit every site.

Tradeoff
Human

Adds a tiny class for one case; only worthwhile when the special case appears in 2+ consumers.

Agent

Adding a Null Object class for a special case used in only one place creates ceremony around what was a one-line check; the agent now loads a class to handle one branch.

Relief
Human

Callers stop branching on identity; the special behavior lives in one place.

Agent

The agent reasons polymorphically; the special behavior lives in one class and consumers don't branch.

Trap
Human

Adding a Null Object (or Special Case) class for a special check used in only one place — creates a class for a one-off conditional.

Agent

Introducing a Null Object class for special checks used in only one place creates a class the agent must load and reason about with no consistency gain.