public abstract class Factory
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
protected |
Factory()
Restrict instantiation to the class itself and subclasses.
|
Modifier and Type | Method and Description |
---|---|
protected abstract java.lang.Object |
create(java.lang.Class implementation)
Creates a new instance of the given class.
|
protected java.lang.Object |
create(java.lang.Class iface,
java.lang.Object type,
boolean singleton)
Create an instance using the given interface and type.
|
protected void |
register(java.lang.Class iface,
java.lang.Object type,
java.lang.Class implementation)
Register a class to implement one type of a specific interface.
|
protected Factory()
protected abstract java.lang.Object create(java.lang.Class implementation) throws java.lang.InstantiationException, java.lang.IllegalAccessException
implementation.newInstance()
.implementation
- the implementation class to be instantiatedjava.lang.InstantiationException
- Thrown when an application tries to create an instance
of a class using the newInstance method in class Class,
but the specified class object cannot be instantiated
because it is an interface or is an abstract class.java.lang.IllegalAccessException
- if an attempt was made to instantiate a of a foreign
package not supporting foreign instantiationprotected java.lang.Object create(java.lang.Class iface, java.lang.Object type, boolean singleton) throws java.lang.InstantiationException
iface
- the desired interface class the type belongs totype
- an object denoting indirectly which concrete
class should be used when instantiatingsingleton
- boolean denoting weather a shared instance
should be usedjava.lang.InstantiationException
- if new instance couldn't be createdprotected void register(java.lang.Class iface, java.lang.Object type, java.lang.Class implementation)
int hashCode()
from java.lang.Object to use
it with Hashtables.iface
- the desired interface class the type belongs totype
- an Object used to distinguish the different implementationsimplementation
- The implementation class being registered