A way to achieve modularity and reusability in OO is through this concept. Multiple languages implement this in different ways. In Python, mixins are supported via multiple inheritance
Mixin is a parent class that provides functionality to subclasses but is not intended to be instantiated itself. It can have both and concrete and abstract methods that are basically abstract base classes. Mixins can be regarded as a specific strain of abstract base classes where they can house both concrete and abstract methods but don't keep any internal states. These can help you when
- You want to provide a lot of optional features for a class.
- You want to provide a lot of not-optional features for a class, but you want the features in separate classes so that each of them is about one feature (behavior).
- You want to use one particular feature in many different classes