mis6 at pitt.edu
Tue Jul 29 16:41:59 CEST 2003
Udo Gleich <udo.gleich at web.de> wrote in message news:<3F262A67.57E4762C at web.de>...
> What I want to do is take *two objects*, derive from both
> their classes, make a new object and combine the state of
> the old objects.
> I dont know if that is a good idea. I would appreciate comments
> on the following solution. Especially the use of the dummy_init
> function as an empty constructor looks not quite right to me.
You may avoid dummy_init and have the default object.__init__ but
this is not the point. The whole construction seems ugly to me.
Do you have the option of using only class variables ? I mean, no
explicit instance dictionary? Then you could simply create the
mixin from the original classes and not merge by hand the
instance dictionaries. Do you have the option of modifying the
original classes to make the all structure more multiple inheritance
friendly? The idea is that one should derive objects from classes,
not classes from objects. What you are doing will probably work,
but It is quite ugly to me.I cannot say more if I have no idea of what
are your constraints. If you cannot touch the original classes,
remember that you can create modifications of them, as mixin-frendly
as you wish. I also have a question: why don't you override the
__init__ method in M in such a way that it calls K1.__init__ and
K2.__init__ according to the number of arguments? That would be
the first thing would come to my mind, but maybe you have reasons
why you don't want that.
More information about the Python-list