Class ClassTypeFactory<T>

  • Type Parameters:
    T - The type of the instances being served by the factory.
    All Implemented Interfaces:
    TypeFactory<T>, org.refcodes.mixin.TypeAccessor<T>

    public class ClassTypeFactory<T>
    extends Object
    implements TypeFactory<T>
    The ClassTypeFactory produces instances of the given Class by invoking the empty constructor. Make sure your provided Class has an empty constructor.
    • Constructor Detail

      • ClassTypeFactory

        public ClassTypeFactory​(Class<T> aClass)
        Constructs a ClassTypeFactory for the given Class.
        Parameters:
        aClass - The Class for which to produce instances.
    • Method Detail

      • createInstance

        public T createInstance()
        This method creates / retrieves an instance of the given type with the given identifier (name) constructed as defined in one to many configuration files. How the instance is configured, created or retrieved is up to the nature (implementation) of the according factory.
        Specified by:
        createInstance in interface TypeFactory<T>
        Returns:
        The instance being fabricated by this factory.
      • getType

        public Class<T> getType()
        This method retrieves the type which the implementing factory produces. In favor to clean instance creation, shortcomings of java's type system are compensated by calling TypeFactory.createInstance()'s Object.getClass() (as we cannot get a generic type's class if not explicitly passed to an instance e.g. through it's constructor). Attention: To avoid unnecessary calls to potentially expensive TypeFactory.createInstance() methods, please overwrite this method.
        Specified by:
        getType in interface org.refcodes.mixin.TypeAccessor<T>
        Specified by:
        getType in interface TypeFactory<T>
        Returns:
        The type of the instances this factory produces.