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 Inte

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

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 > > > > 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 S

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 do

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 workarou

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 w

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

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 practice

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

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 const

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

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 PROTEC

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

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() m

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 -

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 practices

Re: Python Design Patterns

2004-12-02 Thread Dave Cook
"Tony Ha" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Hello Dave, > > Thanks for pointing me to the Cookbook website. > > On 2004-11-29, Tony Ha <[EMAIL PROTECTED]> wrote: > > > > > I wonder, can any Python guru out there translate the Java examples in For anyone tran

Re: Python Design Patterns

2004-11-30 Thread Tony Ha
Hello Dave, Thanks for pointing me to the Cookbook website. Tony Ha. "Dave Cook" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On 2004-11-29, Tony Ha <[EMAIL PROTECTED]> wrote: > > > I wonder, can any Python guru out there translate the Java examples in the > > Should be a g

Re: Python Design Patterns

2004-11-30 Thread Dave Cook
On 2004-11-29, Tony Ha <[EMAIL PROTECTED]> wrote: > I wonder, can any Python guru out there translate the Java examples in the Should be a good exercise, and not just for gurus ;}. > book into Python examples, or write a similar book in Python, perhaps I've also wished for a design patterns bo

Python Design Patterns

2004-11-29 Thread Tony Ha
Hello I am learning Python for in the pass ten months, and have brought a few books about Python. Most of them are good books by its only right, and all of them only teach you how to write Python programs using Python syntax and Python ways, but no one single Python book explicitly teaches you