There are people out there who have the time, motivation, and resources to cook meals entirely from scratch. They’ll turn flour, water, and eggs into pasta and turn cheese, cream, and spices into a sauce. These people make delicious food, but it takes time. Can you imagine how much longer it would take if they also milled the wheat, farmed the chickens, and milked the cows themselves?

When creating software, there’s sometimes a limit to the depth we should go. When pieces of what we’d like to achieve have already been executed well by others, though, it makes a lot of sense to reuse them. Instead of milling wheat and raising cows, we can buy flour and butchered beef. We can start from scratch, but not scratch scratch.

One way to set ourselves up for success in object-oriented programming is through a concept called a mixin. In Python, mixins are supported via multiple inheritance.

Mixins take various forms depending on the language, but at the end of the day they encapsulate behavior that can be reused in other classes.

The delineation between using true inheritance and using mixins is nuanced, but it comes down to the fact that a mixin is independent enough that it doesn’t feel the same as a parent class. Mixins aren’t generally used on their own, but aren’t abstract classes either.