10. Mixins
Overview
Mixins are a mechanism to group a set of zero or more slots for reuse through inheritance. Mixins are like Java/C# interfaces, but can contain concrete methods:
- Mixins are scoped within a pod and globally identified with the qualified name
podName::MixinName
- Mixins contain zero or more uniquely named slots
- Mixins are implicitly abstract
- Mixins may inherit zero or more other mixins
- Mixins cannot declare concrete instance fields
- Mixins cannot declare constructors
- Mixins cannot declare once methods
- Mixins can declare abstract methods
- Mixins can declare concrete instance methods
- Mixins can declare static methods
- Mixins can declare abstract fields
- Mixins can declare static const fields
- Mixins can declare static constructors:
static {}
Mixins are declared using the mixin
keyword:
mixin MyNewMixin {}
To understand how mixins actually work under the covers, take a look at the tour on mixins to see how mixins might look if translated to Java.
Mixin Modifiers
Mixins can be annotated with the public
or internal
modifiers just like classes.
A mixin can be declared with the const
modifier which requires that any class using it must also be const
.
It is a compile time error to use the abstract
or final
modifier with a mixin.