All Known Subinterfaces:
ComponentMixin, RepeaterMixin

public interface Mixin
A poor-man's implementation of mixins, also known as stateful traits, in Java. Interfaces that extend the Mixin superinterface can retrieve state values for the mixin with state(Class, Factory). This obviates the need for hand delegation of an aggregate value when providing an interface implementation for an object that already has a base class. For example, the BaseRepeater class can be used when there is no base class for an object, or RepeaterMixin can be used if there is already a base class. Both achieve the same result, namely implementing the Repeater interface.

Performance Note

Because mixin values are retrieved from an identity map, performance is impacted versus a field implementation and should be considered in design.

Author:
jonathanl (shibo)
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    state​(Class<? extends Mixin> type, Factory<T> factory)
     
  • Method Details

    • state

      default <T> T state(Class<? extends Mixin> type, Factory<T> factory)
      Parameters:
      type - The type of state to associate with this mixin
      factory - Factory that can create a new state to associate with this mixin
      Returns:
      The state for this mixin