- java.lang.Object
-
- org.refcodes.factory.PrototypeFactory<T>
-
- All Implemented Interfaces:
Serializable
,TypeFactory<T>
,org.refcodes.mixin.TypeAccessor<T>
public class PrototypeFactory<T> extends Object implements TypeFactory<T>, Serializable
ThePrototypeFactory
creates instances of a specific type from a prototype instance. Your type must implement either theSerializable
or theCloneable
interface. UseCloneable
for a shallow copy by default, andSerializable
for a deep copy by default.- See Also:
- Serialized Form
-
-
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 PrototypeFactory(T aPrototype)
Constructs the factory with the according type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.Class<T>
getType()
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
createInstance
-
-
-
-
Constructor Detail
-
PrototypeFactory
public PrototypeFactory(T aPrototype)
Constructs the factory with the according type. Your type must implement either theSerializable
or theCloneable
interface. UseCloneable
for a shallow copy by default, andSerializable
for a deep copy by default.- Parameters:
aPrototype
- The prototype to be used as prototype by this factory.
-
-
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 interfaceTypeFactory<T>
- Returns:
- The instance being fabricated by this factory.
-
getType
public Class<T> getType()
Description copied from interface:TypeFactory
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 callingTypeFactory.createInstance()
'sObject.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 expensiveTypeFactory.createInstance()
methods, please overwrite this method.- Specified by:
getType
in interfaceorg.refcodes.mixin.TypeAccessor<T>
- Specified by:
getType
in interfaceTypeFactory<T>
- Returns:
- The type of the instances this factory produces.
-
-