[Tutor] Calling method in parent class

Jeremiah Dodds jeremiah.dodds at gmail.com
Tue May 12 12:32:34 CEST 2009


On Tue, May 12, 2009 at 11:02 AM, The Green Tea Leaf <
thegreentealeaf at gmail.com> wrote:

> > 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.
>
>
>
If your superclass has a method with the same name (other than __init__
here), that contains some logic that a subclass that overrides the method
needs, it's written wrong in python. In this case, use different method
names, or factor out the parent class methods functionality into (probably)
a decorator. Code reuse should be strived for, but that's not the only
purpose of inheritance. If you need to override a method in a subclass, and
still need to call the parents method in that subclass, you're almost
definately using inheritance wrong, with the special exception of __init__.

In the case of __init__, you probably want to use Parent.__init__, and not
super, if only because of all the weird edge cases with super.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090512/a900e5ba/attachment.htm>


More information about the Tutor mailing list