17

Message Chains


Symptom

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

Goal

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

Smellier version
const street = order.customer.address.street;
Fresher version
const street = order.customerStreet();
Savings

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

Note

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