Stop reaching through object chains
Reduce coupling by replacing deep object navigation with direct messages to collaborators.
The break Alerting reached through order, customer, account, card, address, and country. A profile refactor broke a rule that should not know that path. Deep navigation makes internal structure a public dependency. Encapsulation rule Law of Demeter Collaborate with direct objects. Do not make a caller know a whole object graph just to answer one question. Shortcut Chain getters until the value appears Structure can change behind a stable message. A caller should depend on a collaborator's promises, not its internal path. 01 Question 02 Owner 03 Fresh Step 1 The alert needs to know whether the order is billed…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in