[Python-Dev] Things to Know About Super
mal at egenix.com
Wed Aug 27 12:53:16 CEST 2008
On 2008-08-27 09:54, Greg Ewing wrote:
> Do you have a real-life example of this where multiple
> inheritance is actually used?
> A non-contrived example or two would be a good thing to
> have in tutorials etc. where super() is discussed. It
> would help to convey the kinds of situations in which
> use of super() is and is not appropriate.
The typical use is in mixin classes that can be used to
add functionality to base classes, something you often find
in application frameworks, e.g.
class NewComponent(Feature1Mixin, Feature2Mixin, BaseComponent):
If the mixin classes have to override one of the methods defined
in BaseComponent, then they must pay attention to all other mixin
classes used to define the NewComponent.
Without super() (or some other mechanism of accessing the base
method, like e.g. mxTools' basemethod() for classic classes), the
mixins could potentially override methods defined by other mixin
classes which would then not get called.
As example, think of a typical application server method
def process_request(self, request):
To work properly, each implementation of the method in the mixin classes
and base class will have to be called - in the order they were defined
in the class definition.
Professional Python Services directly from the Source (#1, Aug 27 2008)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-Dev