一行代码只出现一个点其实这个原则有个更学术的名字:迪米特法则(The Law of Demeter)。意思就是只和身边的朋友交流,你不要通过点点点获取一个很远的对象的状态,然后再来做些计算。
基于6个网页-相关网页
LoD The Law of Demeter 迪米特法则
The interesting thing about method Pointers is that their use can be an indication that the code violates the Law of Demeter.
关于方法指针,有意思的事情是:它们的使用可能就表明代码违反了迪米特法则。
In Listing 9, you can see how this code demonstrates the Law of Demeter — and how it could be used to wreak havoc with people's wallets!
在清单9中,可以看到这些代码演示了迪米特法则——如何用它洗劫人们的钱包!
Lastly, the closure structure more closely follows the Law of Demeter since your object would, theoretically, be "reaching through" via the prototype chain.
最后,闭合结构更接近于得墨忒耳法自你的对象,从理论上讲,是“通过”通过原型链。
应用推荐