Backend & Runtime / Knowledge library
Law of Demeter
Limits an object to collaborating with its immediate acquaintances
Why learn Law of Demeter?
It reduces knowledge of distant object structure
The problem it solves
It prevents fragile chains of calls across internal boundaries
Where it came from
Law of Demeter is a software design principle that limits an object to collaborating with its immediate acquaintances. Its guarantees and tradeoffs depend on the concrete implementation and operating context.
Build your understanding
Work through these exercises in order. Try the task before opening a reference.
- Define Law of Demeter and distinguish it from a neighboring concept.
- Choose a realistic task where Law of Demeter is appropriate.
- Identify a failure mode caused by misusing Law of Demeter.
- Interpret a small design or result involving Law of Demeter.
- Explain one tradeoff or limitation of Law of Demeter.
Documentation and sources
- Software Engineering at Google (abseil.io)