More formally, the Law of Demeter for functions requires that a method M of an object O may only invoke the methods of the following kinds of objects:
- O itself (方法自身)
- M's parameters (方法参数对象方法)
- any objects created/instantiated within M (方法中创建对象的方法)
- O's direct component objects (对象的实例对象的方法)
- a global variable, accessible by O, in the scope of M (对象方法范围内可以访问的全局变量)
本文详细介绍了软件设计原则中的德米特法则(LoD),该法则限制了对象方法调用的范围,仅允许调用自身、参数对象、内部创建对象、直接组件对象及方法作用域内的全局变量的方法。
293

被折叠的 条评论
为什么被折叠?



