Mixin classes and single/multiple inheritance

Michele Simionato michele.simionato at gmail.com
Thu Sep 20 01:30:09 EDT 2007


On Sep 20, 6:52 am, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> Michele Simionato <michele.simion... at gmail.com> writes:
> > Since the language we have does have multiple inheritance, let's
> > use it to implement mixins.
> > ...
> > So, multiple inheritance is giving us very little for the point of
> > view of mixins; OTOH, multiple inheritance is giving us a lot of
> > headaches for what concerns cooperative methods.
>
> I may be obtuse, but the above statements seem to be professing
> contradictory viewpoints.
>
> Do you think multiple inheritance should or should not be used in
> Python to do what mixins do?

If you want to use mixins in Python, then you should use
multiple inheritance, since multiple inheritance is already
there, no point in reinventing it. OTOH, one may argue that
there are better approaches than mixins, but this is another
topic.

> > My point was that even if Python had been implemented without
> > multiple inheritance, it would have been simple to implement mixins,
> > or by copying the methods, or by dispatching with __getattr__.
>
> Can you give a code example of how you think mixins should be
> implemented in Python, assuming the absence of multiple inheritance?

I have various example somewhere in my hard disk, but now it is time
for me to go to job, so you will have to wait ;) But I
am sure others here can provide examples.

                     Michele Simionato




More information about the Python-list mailing list