Classes, Inheritance - Stupid lazy question
Michael Scharf
Michael.Scharf at gmx.de
Wed Apr 12 21:36:05 EDT 2000
Michael Hudson wrote:
> another option is:
>
> class paul(lazy):
> super = lazy
> def __init__(self, name):
> self.super.__init__(self,name)
> self.april_pay = 0
>
> def fired(self):
> print "Here's a box, collect the things from your desk"
> self.super.fired(self)
>
> Though this has problems with repeated & multiple inheritance.
What happens if you want to inherit from paul?
self.super would be overwritten!
Make super private (__super) and it will work fine.
We use a similar trick in C++ (a private <typedef MySuperClas super>),
so changing the superclass requires only two changes in the header...
#---snip---
class lazy:
def __init__(self, name):
self.name = name
def fired(self):
print 'You are fired %s!' % self.name
class paul(lazy):
__super=lazy
def __init__(self, name):
self.__super.__init__(self,name)
self.april_pay = 0
def fired(self):
print "Here's a box, collect the things from your desk."
self.__super.fired(self)
class michael(paul):
__super=paul
def fired(self):
print self.name, "will fire paul!"
self.__super.fired(self)
lazy("lazy").fired()
print
paul("paul").fired()
print
michael("michael").fired()
#---snap---
Michael
--
''''\ Michael Scharf
` c-@@ TakeFive Software GmbH, a Wind River Company
` > http://www.WindRiver.com
\_ V mailto:Michael.Scharf at gmx.de
More information about the Python-list
mailing list