What are Mixins?

Angelina Wong
2 min readJan 1, 2019

--

Photo by Brooke Lark on Unsplash

So I the term mixins had come up a few times during bootcamp, and every time it just reminded me of Baskin-Robbins. I thought that I was just hungry, but it turns out that the creator also had ice cream on their mind when they were creating mixins! The concept of mixins was created by Howard Cannon for Flavors, an object oriented extension to Lisp (an early high-level programming language). The name came from a ice cream parlour in Massachusetts that called their toppings “mix-ins”.

Now mixins are used in a lot of object oriented programming languages. The idea is similar to the idea of customizing your ice cream. You write some functionality in one class and then mix it in with another class. This lets you re-use your code, helping you keep your code dry and avoiding any messy inheritance. The parent will be the class that has the function that you want to pass down. The child is the class that you are giving the function to.

The biggest difference between typical inheritance and mixins are that the “child” does not have to be a “type of” the parent class to use the function. This also means that only the specific thing that you want to pass down is given. The mixin functionality can also be passed to multiple children.

--

--