Law of Demeter


In OO software, do not assume knowledge of anything else.

Longer explanation

The Law of Demeter (LoD) is the principle of least knowledge for developing software.

Roughly speaking other ways of expressing this are:

  • software should be loosely coupled
  • principle of encapsulation
  • principle of “information hiding”

For modern OO languages, when using dot notation simply use 1 dot. i.e. something like this would be forbidden:


as you’re assuming knowledge.

Much longer explanation here: