Law of Demeter

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 invented at Northeastern University towards the end of 1987, and can be succinctly summarized in one of the following ways:

  • Each unit should have only limited knowledge about other units: only units "closely" related to the current unit.
  • Each unit should only talk to its friends; don't talk to strangers.
  • Only talk to your immediate friends.

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).

It is so named for its origin in the Demeter Project, an adaptive programming and aspect-oriented programming effort. 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.

Read more about Law Of Demeter:  In Object-oriented Programming, Advantages, Disadvantages

Famous quotes containing the words law of, law and/or demeter:

    A crime persevered in a thousand centuries ceases to be a crime, and becomes a virtue. This is the law of custom, and custom supersedes all other forms of law.
    Mark Twain [Samuel Langhorne Clemens] (1835–1910)

    What, then, is the true Gospel of consistency? Change. Who is the really consistent man? The man who changes. Since change is the law of his being, he cannot be consistent if he stick in a rut.
    Mark Twain [Samuel Langhorne Clemens] (1835–1910)

    But the house of the prudent countryman will be, of course, a place of honest manners; and Demeter Thesmophoros is the guardian of married life, the deity of the discretion of wives. She is therefore the founder of civilised order.
    Walter Pater (1839–1894)