Class ClassTypeFactory<T>

java.lang.Object
org.refcodes.factory.ClassTypeFactory<T>
Type Parameters:
T - The type of the instances being served by the factory.
All Implemented Interfaces:
Factory<T>, 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.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.refcodes.mixin.TypeAccessor

    org.refcodes.mixin.TypeAccessor.TypeBuilder<T extends Object,B extends org.refcodes.mixin.TypeAccessor.TypeBuilder<T,B>>, org.refcodes.mixin.TypeAccessor.TypeMutator<T extends Object>, org.refcodes.mixin.TypeAccessor.TypeProperty<T extends Object>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a ClassTypeFactory for the given Class.
  • Method Summary

    Modifier and Type
    Method
    Description
    This method creates / retrieves an instance of the given type.
    This method retrieves the type which the implementing factory produces.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.refcodes.factory.TypeFactory

    create
  • Constructor Details

    • ClassTypeFactory

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

    • create

      public T create()
      This method creates / retrieves an instance of the given type.
      Specified by:
      create in interface Factory<T>
      Returns:
      The instance being fabricated by this factory.
    • getType

      public Class<T> getType()
      This method retrieves the type which the implementing factory produces. Attention: As of shortcomings of java'stype system, by default the Object.getClass() of the Factory.create() result is returned (as we cannot get a generic type's class if not explicitly passed to an instance e.g. through it's constructor). To avoid unnecessary calls to potentially expensive Factory.create() 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.