Vol. I a living index of named laws · est. mmxxvi no ads · no account
The Law Tomeindex of named laws

Is The Law of Demeter real?

rated Heuristic

It is a rule of thumb, not a finding. It is useful and widely relied on, but it was never established by measurement and does not claim to be. The Law of Demeter is rated Heuristic in this index. Its name is occasionally printed in English books, among the 903 whose print frequency can be measured, so this is a question people are actually asking.

The Law of Demeter says: Each unit should talk only to its immediate friends, and never to strangers. 2 sources sit behind the Heuristic rating, 1 of them primary. Below: how far that goes in the entry's own words, and how it compares with the 1,116 entries around it.

Occasionally printed in printed books, of 903 measured names. The others in this band
33 of 69 entries in software & systems rest on something other than measurement, 48% of the field
45% of all 1,116 entries in the index are rated the same way. The best-known are the least likely to rest on measurement

Heuristic a dependable rule of thumb, not a proven theorem

Where it runs out

The standard criticism is the cost of obeying it: propagating calls through wrappers takes time and space at runtime, and done poorly it inflates a class's interface with auxiliary methods that exist only to forward. That is a genuine trade: maintainability bought with complexity and some efficiency. It also does not apply cleanly to data-transfer objects, to fluent interfaces, or to standard-library types whose structure is stable by contract, and mechanical enforcement by counting dots produces false positives in all three.

What people get wrong about it

It is not a law in any sense stronger than a design guideline, and the name is a project name, not a claim to lawfulness. It is not a rule against method chaining as such. And 'don't talk to strangers' does not forbid using objects you were given. Those are friends; strangers are the objects you reach through them to find.

What the claim rests on

  1. "Law of Demeter." Wikipedia — Ian Holland's authorship at Northeastern in 1987, the Demeter Project naming, the formal statement of which methods may be called, and the documented criticisms. secondary
  2. Lieberherr, K. & Holland, I. (1989). "Assuring Good Style for Object-Oriented Programs." IEEE Software 6(5). — the law as published by the Demeter group. primary

Read the full entry on The Law of Demeter

About this verdict

So is The Law of Demeter real or not?

It is a rule of thumb, not a finding. It is useful and widely relied on, but it was never established by measurement and does not claim to be. This index does not rule on truth; it records what kind of support a claim has. Heuristic means a dependable rule of thumb, not a proven theorem. The four ratings in full.

Who decides the rating?

We do, and that is the softest part of this whole index. It is stated on the page that makes the argument rather than buried. The rating is applied against a published scale, the entry's own limits are quoted rather than summarised, and every source is linked so you can disagree with us from the same evidence.

Where is the rest of it?

The full entry has what the idea says, where it came from, how it works, worked examples and what it is often confused with. This page is only the evidence question. Every entry rated the same way is on the Heuristic list.