gov.sandia.cognition.factory
Class DefaultFactory<CreatedType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.factory.DefaultFactory<CreatedType>
Type Parameters:
CreatedType - The type that the factory creates.
All Implemented Interfaces:
Factory<CreatedType>, CloneableSerializable, Serializable, Cloneable

@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 DefaultFactory<CreatedType>
extends AbstractCloneableSerializable
implements Factory<CreatedType>

The DefaultFactory class is a default implementation of the Factory interface that takes a class as its parameter and uses the default constructor of the class, called through newInstance(), to create new objects of that class.

Since:
2.1
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
protected  Class<? extends CreatedType> createdClass
          The class whose default constructor is used to create new objects.
 
Constructor Summary
DefaultFactory(Class<? extends CreatedType> createdClass)
          Creates a new DefaultFactory for the given class.
 
Method Summary
 CreatedType create()
          Creates a new object using the default constructor of the class that the factory contains.
static
<T> DefaultFactory<T>
get(Class<T> createdClass)
          Gets a new DefaultFactory for the given class.
 Class<? extends CreatedType> getCreatedClass()
          Gets the class whose default constructor is used to create new objects.
 void setCreatedClass(Class<? extends CreatedType> createdClass)
          Sets the class whose default constructor is used to create new objects.
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

createdClass

protected Class<? extends CreatedType> createdClass
The class whose default constructor is used to create new objects.

Constructor Detail

DefaultFactory

public DefaultFactory(Class<? extends CreatedType> createdClass)
Creates a new DefaultFactory for the given class.

Parameters:
createdClass - The class whose default constructor is used to create new objects.
Method Detail

create

public CreatedType create()
Creates a new object using the default constructor of the class that the factory contains.

Specified by:
create in interface Factory<CreatedType>
Returns:
A new object of the created class.

getCreatedClass

public Class<? extends CreatedType> getCreatedClass()
Gets the class whose default constructor is used to create new objects.

Returns:
The class whose default constructor is used to create new objects.

setCreatedClass

public void setCreatedClass(Class<? extends CreatedType> createdClass)
Sets the class whose default constructor is used to create new objects. The class cannot be null, an interface, or an abstract class and must have a default constructor.

Parameters:
createdClass - The class whose default constructor is used to create new objects.

get

public static <T> DefaultFactory<T> get(Class<T> createdClass)
Gets a new DefaultFactory for the given class. The class cannot be null, an interface, or an abstract class and must have a default constructor.

Type Parameters:
T - The type of the class.
Parameters:
createdClass - The class whose default constructor will be used in the factory.
Returns:
A new DefaultFactory created for the given class.