[Tutor] What is a mixin class?

Chris Lasher chris.lasher at gmail.com
Wed Jan 17 21:46:19 CET 2007

On 1/17/07, Don Taylor <nospamformeSVP at gmail.com> wrote:
> So, what constitutes a mixin class and what are the conventional ways to
> denote them in code?

A mixin is a specific type of superclass, just called a mixin because
of the concept it represents. A common type of mixin would be a class
that defines some sort of modified functionality intended to be given
to multiple, not necessarily related classes.

Say you wanted all your classes to have a similar looking format when
"print"ed. You could define a mixin class that defined a special
__repr__ method. A detailed  example of this is demonstrated in
/Learning Python/ by Lutz & Ascher.

There's no need to explicitly state that they are a mixin class, but
if you felt the need to, you could either put it in a comment or,
probably even better, in the mixin's docstring.


More information about the Tutor mailing list