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:

    “There is but one law for all, namely that law which governs all law, the law of our Creator, the law of humanity, justice, equity—the law of nature and of nations.”
    —Edmund Burke (1729–1797)

    “And what other great nation has statutes and ordinances as just as this entire law that I am setting before you today? But take care and watch yourselves closely, so as neither to forget the things that your eyes have seen nor to let them slip from your mind all the days of your life; make them known to your children and your children’s children...”
    —Bible: Hebrew, Deuteronomy 4:8,9.

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