Migrated from Posterous.
Demeter’s law helps with encapsulation and information hiding by trying to minimize dependencies between objects. It states:
- Your method can call other methods in its class directly
- Your method can call methods on its own fields directly (but not on the fields’ fields)
- When your method takes parameters, your method can call methods on those parameters directly.
- When your method creates local objects, that method can call methods on the local objects.
In the following youtube video by Jason Gorman you can see a complete refactoring of a code that did not respect the law.