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:
“The respect for human rights is one of the most significant advantages of a free and democratic nation in the peaceful struggle for influence, and we should use this good weapon as effectively as possible.”
—Jimmy Carter (James Earl Carter, Jr.)
“For, the advantages which fashion values, are plants which thrive in very confined localities, in a few streets, namely. Out of this precinct, they go for nothing; are of no use in the farm, in the forest, in the market, in war, in the nuptial society, in the literary or scientific circle, at sea, in friendship, in the heaven of thought or virtue.”
—Ralph Waldo Emerson (18031882)
“If the minds of women were enlightened and improved, the domestic circle would be more frequently refreshed by intelligent conversation, a means of edification now deplorably neglected, for want of that cultivation which these intellectual advantages would confer.”
—Sarah M. Grimke (17921873)