Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Fri Jul 30 23:08:44 EDT 2010
On Fri, 30 Jul 2010 14:43:07 +0200, Jean-Michel Pichavant wrote:
> Quoting Michele's article (I think he's still hanging around this list)
>
> "Readers familiar will single inheritance languages, such as Java or
> Smalltalk, will have a clear concept of superclass in mind. This
> concept, however, has /no useful meaning/ in Python or in other multiple
> inheritance languages".
I have read Michelle Simionato's articles on super in Python. He has
taught me a lot. But on that specific matter, I think he is wrong.
Of course, he is right to say that the concept of *the* superclass is
meaningless in a MI language like Python. If MyClass inherits method
spam() from class A, and inherits method ham() from class B, which is
"the" superclass of MyClass?
But Michelle is wrong to conclude that the problem lies with the concept
of *superclass*. The problem lies with the idea that there is ONE
superclass. By dismissing the entire concept, he is throwing out the baby
with the bathwater.
The useful, and I would argue *correct*, concept of superclass is very
simple. It is a reflection of subclass: if Z is a subclass of A, then A
is a superclass of Z. This follows e.g. superset and subset. We don't
have any problem understanding that a class can have many subclasses. Why
the resistance to the idea that a class can have many superclasses?
Even in a single inheritance language, if we had a class hierarchy
A -> B -> C -> ... -> Y -> Z
it makes perfect sense to describe *all* of A-Y as superclasses of Z,
just as we describe all of B-Z as subclasses of A.
--
Steven
More information about the Python-list
mailing list