Introduce Special Case

Referenced by patterns
Symptom

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

Goal

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

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

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

Tradeoff

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

Relief

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

Trap

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.