[Tutor] What is a mixin class?

Kent Johnson kent37 at tds.net
Wed Jan 17 21:59:58 CET 2007

(resending to the whole list)

Don Taylor wrote:
> I have a vague idea what a mixin class is, I would like to get a better 
> handle on it.
> It is a term that is used quite often in Python circles, but I can't 
> find a definition.
> I guess that because of multiple inheritance Python does not need a 
> formal way of specifying mixin classes so I presume that there is some 
> conventional interpretation/coding that is followed for mixin classes.
> So, what constitutes a mixin class and what are the conventional ways to 
> denote them in code?
> Don.
> I notice that Ruby has single inheritance plus mixin classes so maybe 
> somebody who knows Ruby could throw some light on in what way a mixin is 
> different from normal superclass.

A mixin is a class that is not intended to stand on its own, rather it
adds some behaviour to the class that it is mixed in to. Some discussion

This page
points to SocketServer.ForkingMixin and SocketServer.ThreadingMixin as
examples from the Python standard library.


More information about the Tutor mailing list