On Oct 15, 2004, at 7:36 PM, dataangel wrote:

What's the going argument against it? Makes sense to me.
There are constructions in other languages whereby an call to the
superclass method does not require an explicit name of the current
class. When an inherited method is augmented in a subclass, the call to
the superclass version of the method doesn't require any class
specification; each class knows its own hierarchy.

So in the examples others have given, you'd have:

class A(object):
def theMethod(self):
print "doing A stuff"

def someOtherMethod(self):
print "Some Other A method is running"

class B(A):
def theMethod(self):
print "doing some early B stuff"
print "some final B stuff"

When B is created and its theMethod() is called, it prints as follows:
obj = B()
doing some early B stuff
doing A stuff
some final B stuff
Some Other A method is running

In other words, the B class knows it inherits from the A class. When
the call to super() is encountered, B looks to its superclass for such
a method, and executes it if found. If it has multiple parents, it is
resolved as is normally done with multiple inheritance. When the call
to someOtherMethod() is made, the B object knows that it should execute
that method is its superclass.

Think of it another way: since B can figure out how to execute a call
to a method that doesn't exist in B itself by looking into its class
hierarchy, why can't a call like self.super() execute the code that
would have been executed had the subclass not overridden the method in
the first place?

Ed Leafe

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 9 of 11 | next ›
Discussion Overview
grouppython-list @
postedOct 15, '04 at 2:52p
activeOct 16, '04 at 10:11a



site design / logo © 2022 Grokbase