Monday, May 16, 2011

Law of Demeter

I have to start reading material about Dependecy Injection (aka DI), which is based on Demeter's law:

The Many Forms of Demeter

The formal object form of the law can be summarized as:
A method of an object may only call methods of:
  1. The object itself.
  2. An argument of the method.
  3. Any object created within the method.
  4. Any direct properties/fields of the object.
Each unit should have only limited knowledge about other units: only units "closely" related to the current unit. Or: Each unit should only talk to its friends; Don’t talk to strangers.
This of course leads to the succinct form of the law:
Don’t talk to strangers

No comments:

Post a Comment