public class ObjectFactory
extends java.lang.Object
Factory but does
not support singletons and does not synchronize on Object creation
because implementing classes are usually registerd only once.| Constructor and Description |
|---|
ObjectFactory()
Creates a new ObjectFactory.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
create(java.lang.Class implementation)
Creates a new instance of the given class.
|
java.lang.Object |
create(java.lang.Object type)
Creates an instance of a class implementing the given type.
|
void |
register(java.lang.Object type,
java.lang.Class implementation)
Registers a class as implementation of the given type.
|
public java.lang.Object create(java.lang.Class implementation)
throws java.lang.InstantiationException,
java.lang.IllegalAccessException
implementation - the implementation class to be instantiatedjava.lang.InstantiationException - if the object cannot be instantiatedjava.lang.IllegalAccessException - if the given class cannot be accessed because it
is not in the same package and not publicpublic java.lang.Object create(java.lang.Object type)
throws java.lang.InstantiationException
type - the type identifying the class to be instantiatedjava.lang.InstantiationException - if the instance cannot be createdpublic void register(java.lang.Object type,
java.lang.Class implementation)
int hashCode() from java.lang.Object to be used
it with HashMaps.type - the type identifying the class to be registeredimplementation - the implementation class to be registered