:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Mixins allow domain object behaviour to be encapsulated as a separate class.
This behaviour is then contributed to a target object as an action, property or collection.

Mixins only contribute behaviour, not state.
In the case of a contributed property or collection, these are in effect _derived_.
Behind the scenes a query is run against the contributing object.

The contributee object is injected into the mixin through its (1-arg) constructor.
Note that any type can be used, including interfaces.

The examples contribute to the following class, which holds a simple non-editable "count" integer property:

[source,java]
.MixinVm.java
----
include::MixinVm.java[tags=class]
----
<.> editing disabled; it will be modified through a mixin

The mixins contribute behaviour to list the first N fibonacci numbers.
They don't contribute directly to the concrete `MixinVm` class, however; since all they require is a count value, they instead contribute to the `CountHolder` interface that the `MixinVm` class implements:

[source,java]
.CountHolder.java
----
include::CountHolder.java[tags=class]
----

== Contributed action

The `CountHolder_updateCount` mixin allows the count to be updated within a certain range:

[source,java]
.CountHolder_updateCount.java
----
include::CountHolder_updateCount.java[tags=class]
----
<.> indicates this class is a mixin action
<.> useful lombok annotation to generate the 1-arg constructor
<.> the contributee

== Contributed collection

The `CountHolder_fibonacciSequence` mixin dynamically computes the first N number of fibonacci numbers:

[source,java]
.CountHolder_fibonacciSequence.java
----
include::CountHolder_fibonacciSequence.java[tags=class]
----
<.> indicates this class is a mixin collection
<.> useful lombok annotation to generate the 1-arg constructor
<.> the contributee

== Contributed property

The `CountHolder_explanation` mixin simply provides a property that explains what's going on:

[source,java]
.CountHolder_explanation.java
----
include::CountHolder_explanation.java[tags=class]
----
<.> indicates this class is a mixin property
<.> useful lombok annotation to generate the 1-arg constructor
<.> the contributee

