Mixin

In object-oriented programming languages, a mixin (or mix-in)[1][2][3][4] is a class that contains methods for use by other classes without having to be the parent class of those other classes. How those other classes gain access to the mixin's methods depends on the language. Mixins are sometimes described as being "included" rather than "inherited".

Mixins encourage code reuse and can be used to avoid the inheritance ambiguity that multiple inheritance can cause[5] (the "diamond problem"), or to work around lack of support for multiple inheritance in a language. A mixin can also be viewed as an interface with implemented methods. This pattern is an example of enforcing the dependency inversion principle.

  1. ^ Cite error: The named reference :0 was invoked but never defined (see the help page).
  2. ^ Cite error: The named reference :1 was invoked but never defined (see the help page).
  3. ^ Cite error: The named reference :2 was invoked but never defined (see the help page).
  4. ^ Cite error: The named reference :3 was invoked but never defined (see the help page).
  5. ^ Boyland, John; Giuseppe Castagna (26 June 1996). "Type-Safe Compilation of Covariant Specialization: A Practical Case". In Pierre Cointe (ed.). ECOOP '96, Object-oriented Programming: 10th European Conference. Springer. pp. 16–17. ISBN 9783540614395. Retrieved 17 January 2014.