[Tutor] Law of Demeter example request

Blake Winton bwinton@tor.dhs.org
Wed, 26 Dec 2001 17:52:18 -0500


* Timothy Wilson <wilson@visi.com> [011226 16:55]:
> I *think* I get it, but it would be great if someone would post a brief
> example illustrating the Law of Demeter. Preferably, the example should
> show the same short program in two versions, one obeying the law and
> 2nd ignoring it.

The example I saw was
car.accelerate()
and
car.engine.fuelIntake.increaseGasToAirMixture()

The problem with the second one being that if I start driving an
electric car, I'm going to have to change all my code, instead of
just changing the accelerate method (possibly in a subclass of car).

I'm not sure if he notes the downside of the Law, which is that you
might find yourself having _way_ more methods on your containing
objects than you'ld like to.  I'm not sure what, if any, workarounds
people use.

Later,
Blake.
-- 
9:40pm up 52 days, 21:07, 2 users, load average: 0.02, 0.09, 0.07