inheritance
Duncan Smith
buzzard at urubu.freeserve.co.uk
Thu Jun 12 11:46:15 EDT 2003
I'm in the process of subclassing some functionality of a class that was
getting a bit too big. But a lot of the inherited functions (eg. __mul__())
return objects of the parent type. Initially I had the following code...
class Table(table.NumTable):
def __init__(self, values, variables, id = None):
table.NumTable.__init__(self, values, variables, id)
self.isBarnardised = 0
self.isRandRounded = 0
self.isConvRounded = 0
def __mul__(self, other):
res = table.NumTable.__mul__(self, other)
return Table(res.values, res.variables)
But I have ended up with this ...
class Table(table.NumTable):
isBarnardised = 0
isRandRounded = 0
isConvRounded = 0
def __mul__(self, other):
res = table.NumTable.__mul__(self, other)
return Table(res.values, res.variables)
The questions I have are:
Is there any practical difference between the two?
Is there any alternative to explicitly overloading each of the parent class
functions that return a new instance?
Cheers.
Duncan
More information about the Python-list
mailing list