Preserve Whole Object

Symptom

A function call that pulls several fields out of an object to pass them in — `f(room.lowTemp, room.highTemp, room.humidity)` instead of `f(room)`.

Goal

Instead of pulling several values out of an object to pass them in, pass the object itself.

Before the refactoring

if (room.lowTemp < range.low || room.highTemp > range.high) { /* ... */ }

After the refactoring

if (range.includes(room)) { /* ... */ }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

Adding a new field that the function needs touches every call site; the function's contract is verbose and shifts every time it grows.

Tradeoff

Passing the whole object adds coupling to its full surface — only do this when the called function might reasonably need other parts of the object.

Relief

Signatures shrink; adding a needed field is internal; consumers don't have to plumb new arguments through.

Trap

Passing whole objects when the function only needs one field — introduces unnecessary coupling to the object's full surface.