Each unit should have only limited demetra software download about other units: only units “closely” related to the current unit. Only talk to your immediate friends. It is so named for its origin in the Demeter Project, an adaptive programming and aspect-oriented programming effort.
B, but object A should not “reach through” object B to access yet another object, C, to request its services. In particular, an object should avoid invoking methods of a member object returned by another method. For many modern object oriented languages that use a dot as field identifier, the law can be stated simply as “use only one dot”. The advantage of following the Law of Demeter is that the resulting software tends to be more maintainable and adaptable. Since objects are less dependent on the internal structure of other objects, object containers can be changed without reworking their callers.
Following the Law of Demeter can result in a lower RFC. A multilayered architecture can be considered to be a systematic mechanism for implementing the Law of Demeter in a software system. In a layered architecture, code within each layer can only make calls to code within the layer and code within the next layer down. At the method level, the LoD leads to narrow interfaces, giving access to only as much information as it needs to do its job, as each method needs to know about a small set of methods of closely related objects. Since the LoD exemplifies a specific type of coupling, and does not specify a method of addressing this type of coupling, it is more suited as a metric for code smell as opposed to a methodology for building loosely coupled systems. College of Computer and Information Science, Northeastern University. A Validation of Object-Oriented Design Metrics as Quality Indicators”.