in reply to Re^2: The Pretty Good Idea of Demeter (Was: Definition of Law of Demeter)
in thread Are lvalue methods (as properties) a good idea?
Depends. In other cases it might still be appropriate to replace a->b->foo with a->foo. The question is: does the caller need to be aware of the has-a relationship, or is he really just requesting a service from object a? In that case, the presence of object b would be an implementation detail, and shouldn't be exposed just because b is also an object.
The lesson taught by Demeter is really don't expose your inner objects without good reason. I believe what came to be called the Law was formed in the context of larger class frameworks. In this environment, I would guess, people are likely not to think about distinguishing between public and private class relationships. A reminder is then necessary that relationships are part of the published interface of a class no less than methods and properties are, and so require equal consideration.
Makeshifts last the longest.
|
|---|