Temporary Field

Compare
Symptom
Human

A class field used by only one method, set to null or default the rest of the time.

Agent

A class field the agent finds set to null or default for most of the object's lifetime, populated only inside one method's flow — the agent must verify which methods care.

Goal
Human

The temporary state moves to a dedicated class that exists only when it's relevant.

Agent

Temporary state lives in a dedicated class that exists only when relevant; the agent loads the temporary type only when reasoning about that flow.

Smellier version

class Order {
shippingTrack = null;
ship() {
this.shippingTrack = computeTrack();
}
}

Fresher version

class Order { ship() { return new Shipment(this); } }
class Shipment { /* owns the track */ }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Reader must trace the conditions under which the field is meaningful; null-checks scatter; the field's role is unclear.

Agent

The agent must trace the conditions under which the field is meaningful; null-checks scatter across consumers; class invariants weaken because the field has no defined lifecycle.

Tradeoff
Human

Extracting the temporary state to a dedicated class adds a new type the team must learn; for one-shot uses the class can feel like more ceremony than the original field.

Agent

Extracting a new class adds a type the agent must load to reason about the flow; for genuinely one-shot uses the class is more code than the original field warranted.

Relief
Human

Null-checks vanish; class invariants tighten; the new class has a clear purpose.

Agent

Null-checks vanish; the agent reasons about a class with a clear lifecycle; class invariants tighten so reasoning about the host class doesn't have to consider the unused state.

Trap
Human

Extracting a class for every short-lived field — including ones whose 'temporary' use is genuinely local and well-encapsulated by the host class.

Agent

Extracting a class for every short-lived field — including ones with truly local use — creates new types the agent must load with no comprehension gain over the original encapsulated field.