[Tutor] Multiple inheritance for mixin attributes

Knacktus knacktus at googlemail.com
Mon Aug 16 09:01:58 CEST 2010


Hello everyone,

I've got a question about class design. I want to model classes like 
these (examples):

#####################################################################
class BaseItem(object):

     def __init__(self, ident, name, description):
         self.ident = ident
         self.name = name
         self.description = description

class DataSourceItem(object):

     def __init__(self, ident, name, description, data_source):
         self.ident = ident
         self.name = name
         self.description = description
         self.data_source = data_source

class BaseItemCollection(list):

     def __init__(self, ident, name, description):
         self.ident = ident
         self.name = name
         self.description = description

     def default_version(self):
         return self[-1]

class BaseDataSourceItemCollection(list):

     def __init__(self, ident, name, description, data_source):
         self.ident = ident
         self.name = name
         self.description = description
         self.data_source = data_source

     def default_version(self):
         return self[-1]
#######################################################################

Now, to remove all the duplicated code I could use inheritance. But that 
would lead to multiple inheritance and the question how to initialise 
both superclasses?

I would appreciate some advice about how to model classes like this. 
Personaly, I don't have to use inheritance, but I have no better idea. 
Would you accept at least some duplication to avoid multiple inheritance?

Thanks in advance,

Jan


More information about the Tutor mailing list