Is inheritance broken?

Johann Hibschman johann at physics.berkeley.edu
Wed Mar 28 17:13:08 EST 2001


Jonathan Claggett writes:

> Interesting. Are there conventions for mixin classes which distinguish them
> from normal classes? For example, are mixins not suppposed to use
> inheritance (or at least not use mulitple inheritance)? Thanks for the help,

When I use mixins, I never use inheritance.  The mix-in just provides
methods, to be included into other classes.  There is no enforced
protocol, but I find that useful.

Otherwise, I have to start worrying about how python will search the mix-
ins, and that gets ugly quickly.

I also often define classes which are simply different combinations
of mix-ins, such as

class SpecPlotStepper(SpecMixin, PlotMixin, Stepper):
    pass

I hope that helps.  In theory, I like the way Common Lisp implemented
multiple inheritance, but that would require too much searching given
python's class system.

--J


-- 
Johann Hibschman                           johann at physics.berkeley.edu



More information about the Python-list mailing list