method overriding trick
jima at aspectdv.com
Mon Nov 15 15:21:26 EST 1999
I've been doing the exact same thing
only using _Super instead of _Parent.
I have found it to be a helpful convention.
At 12:58 AM 11/13/99 -0800, Phil Mayes wrote:
>Jeremy Hylton wrote in message
><14378.62498.649973.150075 at bitdiddle.cnri.reston.va.us>...
> >Overriding methods of a base class is a little clunky in Python. You
> >need to explicitly name the base class that implements the method, and
> >you call its as an unbound method, passing self as the first argument.
> >Example: Base.aMethod(self, arg)
>and suggested using
> >class Derived1(Base):
> > super_aMethod = Base.aMethod
> > def aMethod(self, arg):
> > return self.super_aMethod(arg) + 1
> >It doesn't solve the must-name-the-base-class problem, but it helps
> >manage it better. If you keep the override assignments at the top of
> >the class statement, then you only have one place to look in each
> >class when the inheritance hierarchy changes.
>I use a method that doesn't remove the clunkiness, but localises the
>hierarchy to one line:
>_Parent = basedlg.BaseDlg
> def __init__(self, param):
> self.local = param
> _Parent.__init__(self, 2345)
>By using the same name "_Parent" in all modules, less thinking is needed,
>and cut'n'paste coding (what, me?) works better too.
>Phil Mayes pmayes AT olivebr DOT com
>Olive Branch Software - home of Arranger
More information about the Python-list