Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon



Mixins are a feature.

A mixin 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". A mixin can also be viewed as an interface with implemented methods.

Languages with Mixins include Python, Ruby, TypeScript, Julia, Racket, Xtext

Example from Python:
# class EssentialFunctioner(LoggerMixin, object):
Example from Ruby:
module A def a1 end def a2 end end module B def b1 end def b2 end end class Sample include A include B def s1 end end samp = samp.a1 samp.a2 samp.b1
Example from TypeScript:
// class SmartObject implements Disposable, Activatable { } // Note: still need to do some runtime ops to make that work.
Example from Julia:
# Including the same code in different modules provides mixin-like behavior. module Normal include("mycode.jl") end module Testing include("safe_operators.jl") include("mycode.jl") end
Example from Racket:
(mixin (interface-expr ...) (interface-expr ...) class-clause ...)
Example from Xtext:
grammar org.example.domainmodel.Domainmodel with org.eclipse.xtext.common.Terminals
iterators-feature.html 路 mixin-feature.html 路 operator-overloading-feature.html

View source

PLDB - Build the next great programming language 路 v2022 Day 33 Docs Build Acknowledgements Traffic Today Traffic Trends Mirrors GitHub