Law of Demeter

The Law of Demeter (LoD) or principle of least knowledge is a design guideline for developing software, particularly object-oriented programs.

The guideline was proposed by Ian Holland at Northeastern University towards the end of 1987,[1] and the following three recommendations serve as a succinct summary:[2] The fundamental notion is that a given object should assume as little as possible about the structure or properties of anything else (including its subcomponents), in accordance with the principle of "information hiding".

The project was named in honor of Demeter, "distribution-mother" and the Greek goddess of agriculture, to signify a bottom-up philosophy of programming which is also embodied in the law itself.

[3][non-primary source needed] The law dates back to 1987 when it was first proposed by Ian Holland, who was working on the Demeter Project.

Although the LoD increases the adaptiveness of a software system, it may result in having to write many wrapper methods to propagate calls to components; in some cases, this can add noticeable time and space overhead.

[11] On the other hand, at the class level, if the LoD is not used correctly, wide (i.e., enlarged) interfaces may be developed that require introducing many auxiliary methods.

One proposed solution to the problem of enlarged class interfaces is the aspect-oriented approach,[12] where the behavior of the method is specified as an aspect at a high level of abstraction.