LoD questions

Joshua Macy l0819m0v0smfm001 at sneakemail.com
Tue Sep 18 17:56:39 EDT 2001


Try http://c2.com/cgi/wiki?LawOfDemeter for an interesting discussion of 
this.  Basically, I agree with the crowd that says there's no automatic 
benefit to making spam.eggs.ham.rat() into spam.doEggsHamRat(), but if 
you have a lot of that going on in your code there's probably something 
wrong in your design.  It's a signal that you should be asking yourself 
why it is that spam needs to know the internal structure of so many 
other classes?  Are the class responsibilities really divided 
appropriately? Is there a Visitor pattern or something in there trying 
to work its way out?  Are you not taking sufficient advantage of 
polymorphism? Etc.

Joshua


Paul Winkler wrote:

> I've been reading about the Law of Demeter which says, in a nutshell,
> that methods should only talk to their "close friends", a concept
> which seems to be vague by intent.




More information about the Python-list mailing list