Interface TypeFactory<T>

Type Parameters:
T - The type of the instances being served by the factory.
All Superinterfaces:
Factory<T>, org.refcodes.mixin.TypeAccessor<T>
All Known Implementing Classes:
ClassTypeFactory, PrototypeFactory
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface TypeFactory<T> extends org.refcodes.mixin.TypeAccessor<T>, Factory<T>
The TypeFactory defines the functionality which must be provided in order to represent a factory for object creation of a predefined type specified with a generic argument (in contrast to the BeanLookupFactory , which creates instances of an expected type). Many alternative implementations of a TypeFactory may may exist which construct the instances their way.

Having factories that generic as we define it here, we are able to decouple our business logic from any specific framework: Your business logic must not know anything about how the instances are generated. It mainly just needs to know how to use the TypeFactory. It is up to the application "end point", i.e. a command line tool with a main-method or a web-application to finally decide which factory to use.

Depending on the implementation used or configuration provided, the TypeFactory may return singletons or dedicated separate instances when queried for instances.

  • 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>
  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    create(Map<String,String> aProperties)
    This method creates / retrieves an instance of the given type.
    default Class<T>
    This method retrieves the type which the implementing factory produces.

    Methods inherited from interface org.refcodes.factory.Factory

    create
  • Method Details

    • create

      default T create(Map<String,String> aProperties)
      This method creates / retrieves an instance of the given type.
      Parameters:
      aProperties - The properties which are used to configure the fabricated instance (by default the properties are ignored and Factory.create() is called directly).
      Returns:
      The instance being fabricated by this factory.
    • getType

      default 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>
      Returns:
      The type of the instances this factory produces.