Skip to content

Temporary Field

The code smell in which an object carries an instance variable meaningful only during one operation or state yet visible as permanent structural state everywhere — a mismatch between the field's structural scope (every instance) and its validity scope (the subset where it holds a real value).

Core Idea

Temporary field, named by Martin Fowler, is the code smell in which an object carries an instance variable meaningful only during one operation or state — a reset token, a cancellation reason, a transient calculation value — while remaining visible as permanent structural state on every instance, holding null or stale values elsewhere. The mismatch is between the field's structural scope (the whole class, every instance) and its validity scope (the subset where it holds a defined value). The named refactoring extracts a method object whose lifetime matches the field's validity.

Scope of Application

Temporary field lives across the object-oriented-design and data-modelling subfields of software and computing.

  • Object-oriented design — the canonical home: a User carrying reset-token fields, an Order carrying cancellationReason.
  • Database schema design — the relational counterpart: columns meaningful only when other columns take certain values, resolved by normalization.
  • UI / form design — relationship-dependent fields shown regardless of relevance.
  • Type-system-rich functional code — where sum types encode the conditional validity directly.

Clarity

Naming temporary field promotes a scatter of symptoms — "this field is sometimes null," an ignore-it convention, a null-pointer crash — into a single structural diagnosis: the field's structural scope is wider than its validity scope. Holding those two scopes apart tells the reader the null-ness is a designed-in mismatch, not an accident of one path. It also sharpens what to do: the obvious null-check is visibly wrong, since it cements the misalignment; the remedy is structural — split the type so the field lives where it is meaningful.

Manages Complexity

A type with conditionally-meaningful fields generates a diffuse burden manifesting as scattered incidents — a null-pointer crash, NULL rows in a report, an ignore-this convention. Temporary field compresses that scatter to one tracked quantity: the gap between structural and validity scope. The remedy space collapses too, to a short menu selected by the validity scope's shape — method object for a transient operation, state subtype for a mode, associated record for a long-lived conditional, optional type when genuinely optional.

Abstract Reasoning

The smell licenses a diagnostic move (read a scatter of symptoms as one scope mismatch — conditional state encoded as unconditional structure); a predictive move (forecast which coping strategy consumers used and where the next fault surfaces); an interventionist move that rejects the local null-check for a structural relocation; and a decisive boundary-drawing move on the shape of the validity scope that both selects the remedy and separates the smell from meaningful-nullable and documented-precondition look-alikes.

Knowledge Transfer

Within software the smell transfers as mechanism across OO design and adjacent data modelling: the scope-gap diagnostic and the shape-selected remedy menu carry intact, with database normalization as a clean relational counterpart. Beyond software the general balance — the scope of state should match the scope of its validity — recurs in statute drafting, org policy, and configuration, but each domain handles it with its own machinery, not the OO diagnostic. The abstract principle is carried by the parents modularity, abstraction, and cohesion, and may merit a dedicated "state-validity-scope correspondence" prime; "temporary field" stays the OO smell.

Relationships to Other Abstractions

Local relationship map for Temporary FieldParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Temporary FieldDOMAINDomain-specific abstraction: Code Smell — is a kind ofCode SmellDOMAIN

Current abstraction Temporary Field Domain-specific

Parents (1) — more general patterns this builds on

  • Temporary Field is a kind of Code Smell Domain-specific

    Temporary Field is the code-smell species whose always-present field provides defeasible evidence that structural scope exceeds the state item's validity scope.

Hierarchy paths (4) — routes to 4 parentless roots

Neighborhood in Abstraction Space

Temporary Field sits in a sparse region of the domain-specific corpus (92nd percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (309 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-07-12