CreatedType
- The type that the factory creates.@CodeReview(reviewer="Kevin R. Dixon", date="2008-12-02", changesNeeded=false, comments={"I just don\'t think this class will be useful.","However, the implementation is great... if anybody ever finds it useful."}) public class ConstructorBasedFactory<CreatedType> extends java.lang.Object implements Factory<CreatedType>, java.lang.Cloneable
ConstructorBasedFactory
class implements a Factory
that takes a constructor and parameters to that constructor used to create
new objects.Modifier and Type | Field and Description |
---|---|
protected java.lang.reflect.Constructor<? extends CreatedType> |
constructor
The constructor to use to create new objects.
|
protected java.lang.Object[] |
parameters
The parameters to pass to the constructor.
|
Constructor and Description |
---|
ConstructorBasedFactory(java.lang.reflect.Constructor<? extends CreatedType> constructor,
java.lang.Object... parameters)
Creates a new
ConstructorBasedFactory from the given constructor
and parameters. |
Modifier and Type | Method and Description |
---|---|
ConstructorBasedFactory<CreatedType> |
clone() |
CreatedType |
create()
Creates a new object by calling the constructor inside the factory with
the parameters it is configured to take.
|
java.lang.reflect.Constructor<? extends CreatedType> |
getConstructor()
Gets the constructor used to create new objects.
|
java.lang.Object[] |
getParameters()
Gets the parameters that are passed to the constructor to create new
objects.
|
void |
setConstructor(java.lang.reflect.Constructor<? extends CreatedType> constructor)
Sets the constructor to use to create new objects.
|
void |
setParameters(java.lang.Object... parameters)
Sets the parameters that are passed to the constructor to create new
objects.
|
protected java.lang.reflect.Constructor<? extends CreatedType> constructor
protected java.lang.Object[] parameters
public ConstructorBasedFactory(java.lang.reflect.Constructor<? extends CreatedType> constructor, java.lang.Object... parameters)
ConstructorBasedFactory
from the given constructor
and parameters.constructor
- The constructor to use to create new objects.parameters
- The parameters to the constructor.public ConstructorBasedFactory<CreatedType> clone()
clone
in class java.lang.Object
public CreatedType create()
create
in interface Factory<CreatedType>
public java.lang.reflect.Constructor<? extends CreatedType> getConstructor()
public void setConstructor(java.lang.reflect.Constructor<? extends CreatedType> constructor)
constructor
- The constructor used to create new objects. It cannot be null. The
parameters on the factory must be set to match the parameter types
the constructor expects before create is called.public java.lang.Object[] getParameters()
public void setParameters(java.lang.Object... parameters)
parameters
- The parameters to pass to the constructor.