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:

  1. O itself (方法自身)
  2. M's parameters (方法参数对象方法)
  3. any objects created/instantiated within M (方法中创建对象的方法)
  4. O's direct component objects (对象的实例对象的方法)
  5. a global variable, accessible by O, in the scope of M (对象方法范围内可以访问的全局变量)