Law of Demeter
The Law of Demeter is a design principle that limits a component’s knowledge of and interaction with other components’ 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 →
Related concepts
- couplinguses · Coupling is the degree of dependency between software components, including how their behavior, availability, or changes affect one another.
- encapsulationuses · Encapsulation is a software design principle that contains state and implementation details behind a controlled interface, limiting direct access from outside.
- dependencyaddresses · A software dependency is a component, resource, or prerequisite on which another software component or operation relies to function or proceed.
- compositionuses · Composition is a technique for combining simpler functions, components, or operations into a larger structure or behavior.
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.

