Introduce Parameter Object

Referenced by patterns
Compare
Symptom
Human

The same group of fields (low, high; firstName, lastName; street, city, zip) appears as parameters across multiple functions — a clump traveling together with no name.

Agent

The agent sees the same field group appearing across multiple signatures; every site re-parses the same shape and verifies the same ordering.

Goal
Human

Related arguments travel together as one well-named value object that the function (and callers) refer to by name.

Agent

The clump becomes a named value object the agent passes through as a single token; structure validation happens once at construction.

Before the refactoring

function recordTemperature(low, high, value) { /* ... */ }
function alertIfOutOfRange(low, high, reading) { /* ... */ }

After the refactoring

class NumberRange {
constructor(low, high) { this.low = low; this.high = high; }
}
function recordTemperature(range, value) { /* ... */ }
function alertIfOutOfRange(range, reading) { /* ... */ }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Adding a field of the clump touches every signature; callers must remember positional order; the clump's identity stays invisible.

Agent

Adding or reordering a field touches every signature; the agent must find and update each consistently or risk silent positional drift.

Tradeoff
Human

Premature parameter objects hide which fields are actually needed by which method — wait until the clump appears in 3+ places before extracting.

Agent

Constructing the object at every call adds an allocation and a name the agent must learn; if the clump appears in <3 places the wrapper is overhead.

Relief
Human

Adding a related field is one type change instead of touching every call site; intent is named.

Agent

The bundled parameter carries the values together as one typed object; the agent matches one field per name at each call site instead of N positional arguments where a mis-alignment passes the type checker.

Trap
Human

Building parameter objects from coincidental groupings (params that happen to appear together but don't share a domain concept) — adds a class for ceremony without expressing meaning.

Agent

Wrapping coincidental field groups creates fake value objects the agent must construct and destructure with no comprehension gain.