Law of Demeter
Updated 2026-07-30
Summary
The Law of Demeter (LoD) or principle of least knowledge is a design guideline for developing software, particularly object-oriented programs. In its general form, the LoD is a specific case of loose coupling. The guideline was proposed by Ian Holland at Northeastern University towards the end of 19…
Definition
Also known as the 'principle of least knowledge'. An object should have as little knowledge as possible about other objects. Only talk to your immediate friends, do not talk to 'friends of friends'. Scaffold use: - Decoupling thinking: In a company, do not command over the head of subordinates, do not interfere in details across departments. Reducing the coupling between modules (departments) allows the system to avoid total collapse during local chaos.
Introduction
How to use
- Decoupling thinking: In a company, do not command over the head of subordinates, do not interfere in details across departments. Reducing the coupling between modules (departments) allows the system to avoid total collapse during local chaos.
Mechanism
Objects should only communicate with immediate friends, not 'friends of friends', to reduce coupling.
Practice
In progress 0/1Practice this model in one real situation:
Cases
- Refactor to a.doViaB() to hide internal structure.
Common pitfalls
- Over-encapsulation leads to a large number of meaningless wrapper methods.
Sources
Source support: Explicit
References currently contain only Wikipedia links; primary sources still need review.
- en.wikipedia.orghttps://en.wikipedia.org/wiki/Law_of_Demeterverified
account_treeGenealogyexpand_more
PRIVATE NOTES · Only visible to you
SAVED Q&A
ENTRY Q&A · Private saving available
Ask with a clear boundary
thinkingmodels answers from published entry context only.
Your question is sent to thinkingmodels. The answer uses public entry context only.
RELATED MODELS