AI Space

Backend & Runtime / Knowledge library

Law of Demeter

Limits an object to collaborating with its immediate acquaintances

Software design principle

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.

  1. Define Law of Demeter and distinguish it from a neighboring concept.
  2. Choose a realistic task where Law of Demeter is appropriate.
  3. Identify a failure mode caused by misusing Law of Demeter.
  4. Interpret a small design or result involving Law of Demeter.
  5. Explain one tradeoff or limitation of Law of Demeter.

Documentation and sources

Connect the ideas

Explore next

EncapsulationLoose Coupling

Catalog source: technology-maxxing. This page reproduces the existing catalog’s learning material and source links.