Mixin

[2] Mixins are a language concept that allows a programmer to inject some code into a class.

Typically, the mixin will export the desired functionality to a child class, without creating a rigid, single "is a" relationship.

Here lies the important difference between the concepts of mixins and inheritance, in that the child class can still inherit all the features of the parent class, but, the semantics about the child "being a kind of" the parent need not be necessarily applied.

This is also possible with statically typed languages, but it requires constructing a new object with the extended set of methods.

This combination determines that all applicable methods for a generic function will be called and the results will be added.

The concept of mixins is implemented in Ruby by the keyword include to which we pass the name of the module as parameter.

However, this lack of separation between state and behavior has drawbacks: An extend function is used to mix the behavior in:[20] Mixin with using Object.assign() The pure function and delegation based Flight-Mixin Approach Even though the firstly described approach is mostly widespread the next one is closer to what JavaScript's language core fundamentally offers - Delegation.

Two function object based patterns already do the trick without the need of a third party's implementation of extend.

In the Curl web-content language, multiple inheritance is used as classes with no instances may implement methods.

Common mixins include all skinnable ControlUIs inheriting from SkinnableControlUI, user interface delegate objects that require dropdown menus inheriting from StandardBaseDropdownUI and such explicitly named mixin classes as FontGraphicMixin, FontVisualMixin and NumericAxisMixin-of class.

Version 7.0 added library access so that mixins do not need to be in the same package or be public abstract.

Curl constructors are factories that facilitates using multiple-inheritance without explicit declaration of either interfaces or mixins.

[citation needed] Java 8 introduces a new feature in the form of default methods for interfaces.

Default methods help in this case where they can be introduced to an interface any time and have an implemented structure which is then used by the associated classes.

Interfaces combined with aspect-oriented programming can also produce full-fledged mixins in languages that support such features, such as C# or Java.

Additionally, through the use of the marker interface pattern, generic programming, and extension methods, C# 3.0 has the ability to mimic mixins.

It then becomes possible to create a static helper class for specific functionality that defines the extension methods.

Scala has a rich type system and Traits are a part of it which helps implement mixin behaviour.

As their name reveals, Traits are usually used to represent a distinct feature or aspect that is normally orthogonal to the responsibility of a concrete type or at least of a certain instance.

[29] Mixin can be achieved in Swift by using a language feature called Default implementation in Protocol Extension.