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 (对象方法范围内可以访问的全局变量)