blob: 3522898645d282ed720bd1ada6346517401c1db1 [file] [log] [blame]
///////////////////////////////////////////////////////////////
* 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.
///////////////////////////////////////////////////////////////
[[tut-composites-step3,Step 3 - Mixins]]
= Step 3 - Mixins =
Previous step was <<tut-composites-step2>>.
In this step we refactor the Mixin from the previous steps into two, one which serves the behaviour interface and
one which serves the state interface. This makes it possible to reuse the interfaces independently and also makes it
easier to exchange one interface implementation with another. This also allows us to specify the new Mixins as default
implementations of the interfaces by adding @Mixins annotations on them.
Steps for this tutorial:
- Refactor the Mixin into one which implement the behaviour interface and one which implements the state interface. Use the @This injection annotation to allow the behaviour to access the state.
- Add a @Mixins annotations on the behaviour and state interfaces which declare the Mixins as default implementations.
- Remove the @Mixins annotation from the TransientComposite interface.
== Solution ==
Only *HelloWorld.java* remains unchanged.
*HelloWorldComposite.java*
[snippet,java]
----
source=tutorials/composites/src/main/java/org/qi4j/tutorials/composites/tutorial4/HelloWorldComposite.java
tag=solution
----
*HelloWorldBehaviour.java*
[snippet,java]
----
source=tutorials/composites/src/main/java/org/qi4j/tutorials/composites/tutorial4/HelloWorldBehaviour.java
tag=solution
----
*HelloWorldBehaviourMixin.java*
[snippet,java]
----
source=tutorials/composites/src/main/java/org/qi4j/tutorials/composites/tutorial4/HelloWorldBehaviourMixin.java
tag=solution
----
*HelloWorldState.java*
[snippet,java]
----
source=tutorials/composites/src/main/java/org/qi4j/tutorials/composites/tutorial4/HelloWorldState.java
tag=solution
----
*HelloWorldStateMixin.java*
[snippet,java]
----
source=tutorials/composites/src/main/java/org/qi4j/tutorials/composites/tutorial4/HelloWorldStateMixin.java
tag=solution
----
Next step is <<tut-composites-step4>>