On Mon, 20 Apr 2009 12:40:08 -0700, you wrote:
>I wrote a blog post that may be helpful.
>http://www.patmaddox.com/blog/demeter-is-for-encapsulation Basically,
>when you have structural objects as in this case, demeter isn't
>useful.
That's a good example as far as it goes, but I think it makes a
distinction that isn't quite the true distinction. For example, I
remember dragsters from the '60s that had as many as four engines. What
does car.engine.name do in that case? And the car I drive these days has
a pair of electric motors in addition to an internal combustion
engine...
Likewise with the stereo--some minivans and SUVs come with two
independent stereo/entertainment systems, one for the front seat
passengers and one for the rear. When I invoke car.stereo.has_cd_player,
am I asking about the "default" front-seat stereo, or do I only care
whether or not the car has a cd player somewhere?
The point, of course, is that digging down into the structure of an
object, even if structural information is what you're after, requires
that you make assumptions about that structure. And _that_ should be the
criterion. You have to ask yourself:
(a) What implicit assumptions am I making by doing this?
(b) Is is safe to make those assumptions?
If you can reasonably answer yes to the second question, then you're in
good shape. But you still have to accept that future changes to the
design can lead to structural changes that retroactively invalidate your
answer.
-Steve