Coupling, Cohesion and the Law of Demeter

前端 未结 6 1546
南旧
南旧 2020-12-02 05:53

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

6条回答
  •  暖寄归人
    2020-12-02 06:14

    In the situations where there seems to be a tradeoff between coupling and cohesion, I'd probably ask myself "if somebody else had already written this logic, and I were looking for a bug in it, where would I look first?", and write the code that way.

提交回复
热议问题