Re: python's OOP question

2006-10-18 Thread Peter Otten
Neil Cerutti wrote: > On 2006-10-18, neoedmund <[EMAIL PROTECTED]> wrote: >> ivestgating the web, i found something similiar with my approch: >> http://en.wikipedia.org/wiki/Duck_typing >> "Duck-typing avoids tests using type() or isinstance(). Instead, it >> typically employs hasattr() tests" >

Re: python's OOP question

2006-10-18 Thread Neil Cerutti
On 2006-10-18, neoedmund <[EMAIL PROTECTED]> wrote: > ivestgating the web, i found something similiar with my approch: > http://en.wikipedia.org/wiki/Duck_typing > "Duck-typing avoids tests using type() or isinstance(). Instead, it > typically employs hasattr() tests" It's pity it didn't get calle

Re: python's OOP question

2006-10-18 Thread Ben Finney
"neoedmund" <[EMAIL PROTECTED]> writes: > Bruno Desthuilliers wrote: > > neoedmund wrote: > > > in real life, a class is not defined so well that any method is > > > needed by sub-class. > > > > Then perhaps is it time to refactor. A class should be a highly > > cohesive unit. If you find yourself

Re: python's OOP question

2006-10-18 Thread neoedmund
Bruno Desthuilliers wrote: > neoedmund wrote: > (snip) > > So I can reuse a method freely only if it's worth reusing. > > For the word "inheritance", in some aspect, meanings reuse the super > > class, with the condition: must reuse everything from super class. > > Not really. In fact, inheritance

Re: python's OOP question

2006-10-18 Thread Fredrik Lundh
neoedmund wrote: > ivestgating the web, i found something similiar with my approch: > http://en.wikipedia.org/wiki/Duck_typing > "Duck-typing avoids tests using type() or isinstance(). Instead, it > typically employs hasattr() tests" that's not entirely correct, though: in Python, duck-typing typ

Re: python's OOP question

2006-10-18 Thread neoedmund
Bruno Desthuilliers wrote: > neoedmund wrote: > (snip) > > So I can reuse a method freely only if it's worth reusing. > > For the word "inheritance", in some aspect, meanings reuse the super > > class, with the condition: must reuse everything from super class. > > Not really. In fact, inheritance

Re: python's OOP question

2006-10-17 Thread Bruno Desthuilliers
neoedmund wrote: (snip) > So I can reuse a method freely only if it's worth reusing. > For the word "inheritance", in some aspect, meanings reuse the super > class, with the condition: must reuse everything from super class. Not really. In fact, inheritance *is* a special case of composition/deleg

Re: python's OOP question

2006-10-16 Thread neoedmund
On Oct 16, 9:01 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > neoedmund wrote: > > Bruno Desthuilliers wrote: > >> neoedmund wrote: > >> (*PLEASE* stop top-posting - corrected) > >>> Ben Finney wrote: > [Please don't top-post above the text to which you're replying.] > > "neoedmu

Re: python's OOP question

2006-10-16 Thread Bruno Desthuilliers
neoedmund wrote: > Bruno Desthuilliers wrote: >> neoedmund wrote: >> (*PLEASE* stop top-posting - corrected) >>> Ben Finney wrote: [Please don't top-post above the text to which you're replying.] "neoedmund" <[EMAIL PROTECTED]> writes: > I'm trying to achieve a higher level

Re: python's OOP question

2006-10-16 Thread Kay Schluehr
neoedmund wrote: > Could you show some code to help me know how composition/delegation can > be done here? Thanks. Starting with your example C2 might just derive from C1 and perform a supercall: class C1(object): def v(self, o): return "expected "+o class C2(C1):

Re: python's OOP question

2006-10-16 Thread neoedmund
Bruno Desthuilliers wrote: > neoedmund wrote: > (*PLEASE* stop top-posting - corrected) > > > > Ben Finney wrote: > >> [Please don't top-post above the text to which you're replying.] > >> > >> "neoedmund" <[EMAIL PROTECTED]> writes: > >> > >>> I'm trying to achieve a higher level of "reusability"

Re: python's OOP question

2006-10-16 Thread Bruno Desthuilliers
neoedmund wrote: (*PLEASE* stop top-posting - corrected) > > Ben Finney wrote: >> [Please don't top-post above the text to which you're replying.] >> >> "neoedmund" <[EMAIL PROTECTED]> writes: >> >>> I'm trying to achieve a higher level of "reusability". Maybe it >>> cannot be done in python? Can

Re: python's OOP question

2006-10-15 Thread neoedmund
Oh, How great is the solution! ( though i don't know how it works. ) Thank you George. George Sakkis wrote: > neoedmund wrote: > > > python use multiple inheritance. > > but "inheritance" means you must inherite all methods from super type. > > now i just need "some" methods from one type and "so

Re: python's OOP question

2006-10-15 Thread neoedmund
I found a dynamic way to inherite classes: def MixIn(pyClass, mixInClass): if mixInClass not in pyClass.__bases__: pyClass.__bases__ += (mixInClass,) def test1(): o = C3() MixIn(C3,C1) MixIn(C3,C2) o.m() "expected aaa" neoedmund wrote: > thank you, Ka

Re: python's OOP question

2006-10-15 Thread George Sakkis
neoedmund wrote: > python use multiple inheritance. > but "inheritance" means you must inherite all methods from super type. > now i just need "some" methods from one type and "some" methods from > other types, > to build the new type. > Do you think this way is more flexible than tranditional inh

Re: python's OOP question

2006-10-15 Thread Gregor Horvath
neoedmund schrieb: > python use multiple inheritance. > but "inheritance" means you must inherite all methods from super type. > now i just need "some" methods from one type and "some" methods from > other types, > to build the new type. > Do you think this way is more flexible than tranditional in

Re: python's OOP question

2006-10-15 Thread neoedmund
python use multiple inheritance. but "inheritance" means you must inherite all methods from super type. now i just need "some" methods from one type and "some" methods from other types, to build the new type. Do you think this way is more flexible than tranditional inheritance? Ben Finney wrote:

Re: python's OOP question

2006-10-15 Thread Ben Finney
[Please don't top-post above the text to which you're replying.] "neoedmund" <[EMAIL PROTECTED]> writes: > I'm trying to achieve a higher level of "reusability". Maybe it > cannot be done in python? Can anybody help me? What, specifically, are you trying to achieve? What problem needs solving?

Re: python's OOP question

2006-10-15 Thread neoedmund
I'm trying to achieve a higher level of "reusability". Maybe it cannot be done in python? Can anybody help me? Ben Finney wrote: > "neoedmund" <[EMAIL PROTECTED]> writes: > > > There's a program, it's result is "unexpected aaa", i want it to be > > "expected aaa". how to make it work? > > > > [co

Re: python's OOP question

2006-10-15 Thread neoedmund
thank you, Kay. But i need a "dynamic" way. Say i have a existing class, and add some method from other class into it. Kay Schluehr wrote: > neoedmund wrote: > > There's a program, it's result is "unexpected aaa", i want it to be > > "expected aaa". how to make it work? > > > > [code] > > > > cl

Re: python's OOP question

2006-10-15 Thread Kay Schluehr
neoedmund wrote: > There's a program, it's result is "unexpected aaa", i want it to be > "expected aaa". how to make it work? > > [code] > > class C1(object): > def v(self, o): > return "expected "+o > > class C2(object): > def v(self, o): > return "unexpecte

Re: python's OOP question

2006-10-15 Thread Ben Finney
"neoedmund" <[EMAIL PROTECTED]> writes: > There's a program, it's result is "unexpected aaa", i want it to be > "expected aaa". how to make it work? > > [code] > > class C1(object): > def v(self, o): > return "expected "+o > > class C2(object): > def v(self, o): >

python's OOP question

2006-10-15 Thread neoedmund
There's a program, it's result is "unexpected aaa", i want it to be "expected aaa". how to make it work? [code] class C1(object): def v(self, o): return "expected "+o class C2(object): def v(self, o): return "unexpected "+o def m(self):