interface @Mixins

The @Mixins annotation is for Composites and MixinTypes. It declares which implementation classes should be used for the found MixinTypes. Implementations for the same MixinType is allowed, and used for overriding purposes. The nearer to the Composite root the higher the precedence.

Description

The @Mixins annotation is central to the composition of the Composite. It will declare exactly which Mixins to use in the Composite, as well as the precedence of Mixin method overrides.

The Mixins will be evaluated from left-to-right as they are declared within the @Mixins annotation, and the each super interface will be scanned likewise. It is also possible to declare Mixins on Mixin implementation classes, typically to declare private Mixins needed by a Mixin. The @Mixins declared on Mixin implementations will be evaluated after the @Mixin declarations in the interfaces.

Precedence means that the first Mixin implementation found to satisfy a MixinType method will be used. Interfaces are searched before classes and Mixins implementing the MixinType will be selected before GenericMixins.

Declaration

package org.qi4j.composite;

@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.TYPE )
@Documented
public @interface Mixins
{
    Class[] value();
}

Example

@Mixins( { MyStuff.class, PropertyMixin.class } )
public interface MyStuffComposite extends Composite, MyStuff, OtherStuff
{}

public interface MyStuff
{
    void doStuff();
}

public interface OtherStuff
{
    Property<String> stuff();
}

public class MyStuffMixin
    implements MyStuff
{
    public void doStuff()
    {
        // impl code goes here.
    }
}

Powered by SiteVisionexternal link.