Qi4j

Tutorial 3 - Mixins

In this tutorial 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:

  1. 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.
  2. Add a @Mixins annotations on the behaviour and state interfaces which declare the Mixins as default implementations
  3. Remove the @Mixins annotation from the Composite interface

Solution

If you have successfully completed the task, you should end up with the following artifacts;

HelloWorld.javaexternal link
HelloWorldBehaviour.javaexternal link
HelloWorldBehaviourMixin.javaexternal link
HelloWorldComposite.javaexternal link
HelloWorldState.javaexternal link
HelloWorldStateMixin.javaexternal link

Powered by SiteVisionexternal link.