Message Chains

Referenced by patterns
Compare
Symptom
Human

Long dotted access paths: a.b.c.d.e — every callsite walks the entire object graph.

Agent

Long dotted access paths the agent must trace through several object hops to understand any single read; renaming any intermediate field breaks every caller silently.

Goal
Human

Callers ask the closest object for what they want; the object delegates internally.

Agent

Callers ask the closest object for what they want; the agent reads one method signature instead of walking N link types to predict what the chain produces.

Smellier version

const street = order.customer.address.street;

Fresher version

const street = order.customerStreet();
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Every link in the chain is a coupling point; renaming any intermediate field breaks every consumer.

Agent

Every link in the chain is a coupling point the agent must hold in working memory; refactoring any intermediate shape requires the agent to find and update every chained access.

Tradeoff
Human

Hiding the delegate adds a passthrough method on the host class for every chained operation; if the chain is used in only one place, the passthrough is pure ceremony.

Agent

Adding passthrough methods on the host class grows its surface; for chains used in one place the passthrough is overhead the agent now maintains in two places.

Relief
Human

Encapsulation tightens; intermediate objects can change shape without breaking callers.

Agent

Encapsulation tightens; intermediate objects can change shape without breaking callers; the agent reasoning about a caller doesn't load every link in the chain.

Trap
Human

Wrapping every dotted chain in passthrough methods — the chains migrate from call sites into the host class's surface, which then balloons with delegations that add no real value.

Agent

Wrapping every dotted chain in passthroughs migrates the smell from call sites into the host class's surface — the agent now reads a wall of delegation methods to find any real behavior.