How do I extend a class that I never instantiate myself?

Gregory Ewing greg.ewing at canterbury.ac.nz
Sat Oct 10 20:03:41 EDT 2015


Laura Creighton wrote:
> don't fear mixins and multiple
> inheritance unduly.  They are a practical solution for a lot of
> problems.  You might have one of them.

I don't think mixins are a solution here, because they
still require controlling the instantiation of the classes
so that you can substitute a class that incorporates the
mixin.

This seems like a case of "adding new operations to
existing things", for which the functional style is
appropriate.

If dispatching on the classes of the objects is needed,
perhaps some implementation of generic functions may
be of help, such as functools.singledispatch in Python
3.4, or PEAK-Rules.

-- 
Greg



More information about the Python-list mailing list