Re: Python Design Patterns - composition vs. inheritance

2007-11-18 Thread Odalrick
On 17 Nov, 19:58, Carl Banks [EMAIL PROTECTED] wrote: Google for Liskov Substitutability if you are interested. I didn't pull this idea out of my hat. In fact I learned the term from reading a post by GvR himself, though the idea was intuitive to me long before that. Carl Banks

Re: Python Design Patterns - composition vs. inheritance

2007-11-17 Thread Odalrick
On 16 Nov, 16:35, Carl Banks [EMAIL PROTECTED] wrote: On Thu, 15 Nov 2007 21:25:16 -0800, Dennis Lee Bieber wrote: On Thu, 15 Nov 2007 16:57:57 -0800 (PST), Carl Banks [EMAIL PROTECTED] declaimed the following in comp.lang.python: A source of confusion with is a is that it doesn't

Re: Python Design Patterns - composition vs. inheritance

2007-11-17 Thread Matthieu Brucher
Well, you would if you override the two set_* methods to set both height and width to the same value G But that breaks expectations: a user doesn't expect set_width() to affect the height. I can't speak for everyone but I certainly expect setting the width of a Square to change

Re: Python Design Patterns - composition vs. inheritance

2007-11-17 Thread Neil Cerutti
On 2007-11-17, Odalrick [EMAIL PROTECTED] wrote: But that breaks expectations: a user doesn't expect set_width() to affect the height. I can't speak for everyone but I certainly expect setting the width of a Square to change it's height. In fact, that would probably be the reason I used a

Re: Python Design Patterns - composition vs. inheritance

2007-11-16 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : In learning about design patterns, I've seen discussion about using inheritance when an object's relationship to another object is 'is-a' and composition when the relationship is 'has-a'. wrt/ inheritance, it only makes sens with declarative static type systems

Re: Python Design Patterns - composition vs. inheritance

2007-11-16 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (snip) It's hard to apply some of the available material's examples to Python since a lot of the documentation I find is specific to implementations in lower-level languages and don't apply to Python. Fact is that quite a few design patterns are mostly workaround

Re: Python Design Patterns - composition vs. inheritance

2007-11-16 Thread A.T.Hofkamp
On 2007-11-15, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: inheritance when an object's relationship to another object is 'is-a' and composition when the relationship is 'has-a'. Since this is all new and I'm still learning, I was hoping someone can give me some pointers on best practices on

Re: Python Design Patterns - composition vs. inheritance

2007-11-16 Thread Neil Cerutti
On 2007-11-16, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Thu, 15 Nov 2007 12:28:28 -0800 (PST), [EMAIL PROTECTED] [EMAIL PROTECTED] declaimed the following in comp.lang.python: As a very simplified example, if I had two classes, Pet and Owner, it seems that I would not have Pet inherit

Python Design Patterns - composition vs. inheritance

2007-11-15 Thread [EMAIL PROTECTED]
In learning about design patterns, I've seen discussion about using inheritance when an object's relationship to another object is 'is-a' and composition when the relationship is 'has-a'. Since this is all new and I'm still learning, I was hoping someone can give me some pointers on best

Re: Python Design Patterns - composition vs. inheritance

2007-11-15 Thread Diez B. Roggisch
As a very simplified example, if I had two classes, Pet and Owner, it seems that I would not have Pet inherit from Owner, since a pet 'has an' owner, but not 'is an' owner. If this is correct, does my code below reflect this? I passed the owner object into the pet object's constructor - is

Re: Python Design Patterns - composition vs. inheritance

2007-11-15 Thread Carl Banks
On Nov 15, 3:37 pm, Diez B. Roggisch [EMAIL PROTECTED] 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

Re: Python Design Patterns - composition vs. inheritance

2007-11-15 Thread [EMAIL PROTECTED]
Yes. Of course there are other ways, establishing the connection later, and of course making the Owner know her pets. But your unidirectional, ctor-passed implementation is sensible. I think my main concern while getting my toes wet on this was to not reference the owner object out of thin air

Fwd: Python Design Patterns - composition vs. inheritance

2007-11-15 Thread Matthieu Brucher
Sorry for the double post -- Forwarded message -- From: Matthieu Brucher [EMAIL PROTECTED] Date: 15 nov. 2007 23:38 Subject: Re: Python Design Patterns - composition vs. inheritance To: [EMAIL PROTECTED] [EMAIL PROTECTED] 2007/11/15, [EMAIL PROTECTED] [EMAIL PROTECTED

Re: Python Design Patterns - composition vs. inheritance

2007-11-15 Thread Chris Mellon
On Nov 15, 2007 2:37 PM, Diez B. Roggisch [EMAIL PROTECTED] wrote: As a very simplified example, if I had two classes, Pet and Owner, it seems that I would not have Pet inherit from Owner, since a pet 'has an' owner, but not 'is an' owner. If this is correct, does my code below reflect

Re: Python Design Patterns - composition vs. inheritance

2007-11-15 Thread Diez B. Roggisch
I think my main concern while getting my toes wet on this was to not reference the owner object out of thin air but to pass it in when pet is instantiated. I'm not sure what 'actor-passed' is yet, but it gives me something to search for and learn about. I meant ctor, short-hand for

Re: Python Design Patterns - composition vs. inheritance

2007-11-15 Thread Carl Banks
On Nov 15, 3:28 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: My response ended up being pretty long and heavy for a beginner, but you sound pretty smart. In learning about design patterns, I've seen discussion about using inheritance when an object's relationship to another object is