When is a subclass not right?
Simon Forman
rogue_pedro at yahoo.com
Thu Aug 24 17:41:04 EDT 2006
Chaz Ginger wrote:
> I was writing some code that used someone else class as a subclass. He
> wrote me to tell me that using his class as a subclass was incorrect. I
> am wondering under what conditions, if ever, does a class using a
> subclass not work.
>
> Here is an example. For instance the original class might look like:
>
> class A :
> def __init__(self,arg) :
> self.foo = arg
> def bar(self) :
> return self.foo
>
>
> And I defined a class B1 which looked like:
>
>
> class B1(A);
> def __init__(self,a1,a2) :
> self.c = a1
> A.__init__(self,ag)
>
>
> He said I should use it this way:
>
> class B2:
> def __init__(self,a1,a2):
> self.c = a1
> self.t = A(a2)
>
> def bar(self) :
> self.t.bar()
>
>
> Other than the obvious difference of B2 having an attribute 't', I can't
> see any other obvious differences. Is there something I am missing?
>
> TIA
> Chaz
When the developer *tells* you it won't work, that's a good indication.
:-)
You haven't missed anything: the developer was talking about his
specific code, not python in general. (I'm on the Twisted list too.
;-) )
Peace,
~Simon
More information about the Python-list
mailing list