Law of Demeter
The Law of Demeter is a software design principle that limits an object’s knowledge of and communication with other objects, especially their internal structure.
Object-Oriented Software Design in C++
The Law of Demeter is a software design principle that limits how much implementation knowledge and object-structure navigation a component exposes or relies upon.
- How it is used
- Guides class design toward loose coupling by limiting dependencies on other objects’ implementations.
- How deep it goes
- Defines four legal call relationships and connects them to private members, encapsulation, and change isolation.
- Examples
- Uses C++ classes named DemeterAuto, Engine, and Sparkplug to contrast direct calls with returned-object navigation.
- What you can do after
- Apply it to expose necessary behavior while avoiding calls through objects returned by other objects.
Read how Object-Oriented Software Design in C++ explains Law of Demeter →
Software Design for Python Programmers
The Principle of Least Knowledge is a design principle that minimizes a class's knowledge of other classes' implementations and thereby reduces dependencies between classes.
- How it is used
- Guides class design toward hidden implementations, loose coupling, and changes that remain localized.
- How deep it goes
- Defines four method-call rules and demonstrates their consequences, but stops short of formal metrics for coupling.
- Examples
- Uses Catalogue, Attributes, Book, DemeterAuto, Engine, and Sparkplug examples to contrast delegation with chained access.
- What you can do after
- Evaluate method calls for problematic object reach-through and design narrower public operations that preserve implementation freedom.
Read how Software Design for Python Programmers explains Law of Demeter →
What to know first
- encapsulationEncapsulation is a software design principle that contains data and implementation details behind a controlled interface, restricting direct access to internal state.
- stateState is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
- inheritanceInheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
- couplingCoupling is the degree of interdependence between software components, including their dependencies on one another’s structure, behavior, or availability.
Related concepts
- couplinguses · Coupling is the degree of interdependence between software components, including their dependencies on one another’s structure, behavior, or availability.
- encapsulationuses · Encapsulation is a software design principle that contains data and implementation details behind a controlled interface, restricting direct access to internal state.
- dependencyaddresses · A dependency is a component, resource, or prerequisite that another software component or activity relies on to function, build, or proceed.
- compositionuses · Composition is the construction of a larger behavior, computation, or system by combining smaller functions, components, or operations.
Questions about Law of Demeter
What is Law of Demeter?
The Law of Demeter is a software design principle that limits an object’s knowledge of and communication with other objects, especially their internal structure.
Which Manning books explain Law of Demeter?
Object-Oriented Software Design in C++ and Software Design for Python Programmers.
What should I know before learning Law of Demeter?
Manning books that teach Law of Demeter usually introduce encapsulation, state, inheritance and coupling first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

