Mixins

Learn about mixins and how to use them.

We'll cover the following

A mixin in Python is a class that gets mixed into another class. It helps with code organization and allows the programmer to move a particular functionality out of a class and into an auxiliary class. To understand this better, let’s take a look at an example.

Previously, we discussed the Dataset abstract base class. We discussed why it was a good idea to keep the interface definitions of load and save in the base class. However, this led to the implementation of load and save in all child classes. We recognized that loading and saving are operations that all datasets should have, so this is a good place to use a mixin. The following code demonstrates how to use a mixin.

Get hands-on with 1400+ tech skills courses.