Mixin classes and single/multiple inheritance

Michele Simionato michele.simionato at gmail.com
Thu Sep 20 06:40:33 CEST 2007


On Sep 20, 5:41 am, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> Michele Simionato <michele.simion... at gmail.com> writes:
> > Ben Finney wrote:
> > > What do you see as an appropriate use of mixin classes, and what
> > > an abuse?
>
> > An example of fine usage of mixin is Tkinter; an example of bad
> > usage if Zope 2.
>
> Which parts of those two very large code sets do I need to look at to
> see the examples you have in mind? I was hoping you could demonstrate
> with short code examples.

Unfortunately you see the issue only when you program in
the large. Take for instance the Plone BaseContent class; I believe
its MRO contains something like 35 classes (I don't remember
the exact number now) in a multiple inheritance hierarchy.
Instances have some something like 400+ methods and attributes.
Now try to understand from which of the parent classes the
attributes came. For Tkinter things are much easier, see
the effbot "Introduction to Tkinter" for a discussion of
the mixin classes it uses.  Then try something like
inspect.getmro(Tkinter.Label) , there are only 7 classes
in the hierarchy. Notice that even with single inheritance
you can run in deep hierarchies (Java docet).The problem,
as Guido once said, is the "inheritance is overrated".

   Michele Simionato





More information about the Python-list mailing list