Lod — Law of Demeter

By | February 29, 2020

Law Demeter

Talk only with your close friends.

Avoid code like that: School.GetWorkers().GetPersonData().GetName(). Every method can only call methods of:

  • Its object.
  • Parameters of its method.
  • Objects, which it creates.
  • Fields of its object

Advantages

  • Less dependency between classes and modules.
  • Easier maintenance.
  • Lack of knowing details of calling objects.

Disadvantages

  • Classes should have more methods.

All posts from mini project: Learn SOLID and OOP principles:

Sources

Main image

Materials

Leave a Reply

Your email address will not be published. Required fields are marked *