A mixin is a way to enhance an object with properties or methods from another object.
Mixins are related to inheritance in that an object receives properties or methods from another object but are typically not limited in number. They are often used as a way to "tack on" behavior to objects rather then to say that objects are related to each other.
For example, we may have an
Album class. Since an album has multiple tracks, we may want to enumerate through it; however, it is also very similar to our
Single class. In our design, we may then inherit from
Single, but also choose to mix in
Enumerable, a mixin that defines mechanisms for enumerating an object.