Overview - Law of Demeter
What is it?
The Law of Demeter is a design guideline for writing software that limits how much one part of a program knows about other parts. It says that a module should only talk to its immediate friends, not friends of friends. This helps keep code simple and easier to change. It is sometimes called the principle of least knowledge.
Why it matters
Without this rule, code becomes tightly connected and hard to fix or improve because changes in one place ripple everywhere. Imagine a machine where every part depends on many others; if one breaks, the whole stops. The Law of Demeter helps avoid this by keeping parts independent and easier to manage.
Where it fits
Before learning this, you should understand basic programming concepts like functions, objects, and modules. After this, you can learn about design patterns and software architecture principles that build on keeping code clean and modular.