41
Hide Delegate
Goal
Callers ask the closest object for what they want; the object delegates internally without exposing its collaborators.
Before the refactoring
const street = order.customer.address.street;After the refactoring// inside Order: customerStreet() { return this.customer.address.street; }
const street = order.customerStreet();Savings
Encapsulation tightens; intermediate objects can change shape without breaking callers.
Note
Adds a passthrough method on the parent for every delegated operation — only worth it for operations that are repeated across consumers.