[Tutor] Calling method in parent class

The Green Tea Leaf thegreentealeaf at gmail.com
Tue May 12 12:02:54 CEST 2009


> That should not happen! Basic contract is: same name = same meaning.

Same meaning yes, but that doesn't mean that I can't/shouldn't reuse
code that address a part of the problem.

> Having two methods with the name that both need two be used on the same object is clearly a design flaw. What do you think?

It think that it depends, as you write yourself if I have a method
that does something that needs/should be done I think it's perfectly
OK to do it (in fact that it should be done).

> The only case is when the parent method performs a part of what child class methods have to do. E.g a common case for __init__:

Exacly, this is the prime example (and I can't come up with another
right now without inventing some convoluted example that would be
really silly)

> class OneChild(Parent):
>        def __init__(self,arg0,arg1):
>                Parent.__init__(self,arg0)
>                self.arg1 = arg1

So this is the preferred way? Not super(OneChild, self).__init__ ?

-- 
The Green Tea Leaf   thegreentealeaf at gmail.com   thegreentealeaf.blogspot.com


More information about the Tutor mailing list