Python Design Patterns - composition vs. inheritance
pavlovevidence at gmail.com
Thu Nov 15 22:49:10 CET 2007
On Nov 15, 3:37 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> > Also, I've seen talk that ideally you shouldn't have too many "dots"
> > in your method calls, instead using delegates to the methods and
> > attributes. Can anyone elaborate on this? Ideally, should I be writing
> > getattr() methods so I can do pet.address instead of
> > pet.owner.address? Should I be doing the same with owner's methods
> > like I did with get_foo()?
> No, that's certainly not a good idea. And I'm under the impression you
> misunderstood something there in the original lecture/explanation.
Having read lots of "perspectives" on OO style, it wouldn't surprise
me if the OP understood the point perfectly.
I.e., there probably are people out there who suggest that when you
have something like this:
you should reverse-refactor it into something like this:
I would agree that the former is preferable, especially in cases like
this one where the classes aren't really closely related.
More information about the Python-list