感觉就像我走到了尽头.如果我理解它,那么如果我遵循
Law of Demeter,我永远不会创建一个返回对象的方法,然后客户端代码调用它.我只是在考虑总是返回一个对象的工厂模式.是的,有一些返回对象的映射器类.收藏怎么样?
你误解了
Law of Demeter并且正在应用它超出实用性:
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