Law of Demeter - Advantages

Advantages

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.

Basili et al. published experimental results in 1996 suggesting that a lower Response For a Class (the number of methods potentially invoked in response to calling a method of that class) can reduce the probability of software bugs. Following the Law of Demeter can result in a lower RFC. However, the results also suggest that an increase in Weighted Methods per Class (the number of methods defined in each class) can increase the probability of software bugs. Following the Law of Demeter can also result in a higher WMC; see Disadvantages.

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. "Layer skipping" would violate the layered architecture.

Read more about this topic:  Law Of Demeter

Famous quotes containing the word advantages:

    There is no one thoroughly despicable. We cannot descend much lower than an idiot; and an idiot has some advantages over a wise man.
    William Hazlitt (1778–1830)

    In 1845 he built himself a small framed house on the shores of Walden Pond, and lived there two years alone, a life of labor and study. This action was quite native and fit for him. No one who knew him would tax him with affectation. He was more unlike his neighbors in his thought than in his action. As soon as he had exhausted himself that advantages of his solitude, he abandoned it.
    Ralph Waldo Emerson (1803–1882)

    No advantages in this world are pure and unmixed.
    David Hume (1711–1776)