The counterexample in C is:
Foo::bar( Baz* baz)
{
baz ()->blargh()->pants()->soil(); // this is bad, Foo knows about blarghs and pants
}
Does this principle have a name? Also, the actual principle instead of my above paraphrase would be nice to see.
The Law of Demeter (LoD), or Principle of Least Knowledge, is a design guideline for developing software, particularly object-oriented programs. The guideline was invented at Northeastern University towards the end of 1987, and can be succinctly summarized as “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).
There are some object-oriented engineering principles, which express a sentence: “A class should only know it as a parameter The contract of the class used, or any internal contract it uses.”
The counterexample in C is:
Foo:: bar( Baz* baz)
{
baz()->blargh()->pants()->soil(); // this is bad, Foo knows about blarghs and pants
}
Does this principle have a name? Also, the actual principles instead of my above paraphrase would be nice to see.
Law of demeter thanks Jim Burger for saying:
< p>
The Law of Demeter (LoD), or Principle of Least Knowledge, is a design guideline for developing software, particularly object-oriented programs. The guideline was invented at Northeastern University towards the end of 1987, and can be succinctly summarized as “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).