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 proposed at
Northeastern University towards the end of 1987, and can be succinctly summarized in each 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.