law-of-demeter

Coupling, Cohesion and the Law of Demeter

半世苍凉 提交于 2019-11-26 17:56:29
问题 The Law of Demeter indicates that you should only speak to objects that you know about directly. That is, do not perform method chaining to talk to other objects. When you do so, you are establishing improper linkages with the intermediary objects, inappropriately coupling your code to other code. That's bad. The solution would be for the class you do know about to essentially expose simple wrappers that delegate the responsibility to the object it has the relationship with. That's good. But,