|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.meta.reflect.TypeLiteral<T> dk.rode.thesis.meta.reflect.InstantiableTypeLiteral<T> dk.rode.thesis.factorymethod.Factory<T>
T
- The product type created by this factory.@Participant(value="Creator") public abstract class Factory<T>
A generic factory that will create products of type T
.
Usage: to create instances of Foo<String>
using the constructor
accepting a String
and int
argument, in that order:
// Create factory... Factory<Foo<String>> factory = newThe constructor to create new instances ofFactory
(String.class, Integer.class){}; // anonymous class // Create products... Foo<String> foo = factory.newInstance
("Bar", 42); Foo<String> foobar = factory.newInstance
("FooBar", 117);
T
is
fetched ignoring primitive types, e.g. a formal parameter type
of Integer
will match both Integer
and int
.
Implementation notes:
This factory is classified as a Factory Method, not an
Abstract Factory,
because its traits most closely resemble those described for Factory
Method by Gamma et al. [Gamma95, p.107-116], but it is a judgement call.
We see it as a variant of the Creator class [Gamma95, p.113], which
uses templates to determine the actual type of product to create. We still
use it in the Abstract Factory implementation as well, though. These are
the reasons why it is named Factory
, and not Creator
.
The PrototypicalFactory
shows how the
Prototype pattern can
often be used as an alternative to reflection.
InstantiableTypeLiteral
,
TypedFactory
Field Summary |
---|
Fields inherited from class dk.rode.thesis.meta.reflect.TypeLiteral |
---|
type |
Constructor Summary | |
---|---|
protected |
Factory(Class<?>... parameterTypes)
Constructor, which creates this factory to create instances of the type represented by the type parameter T using
the declared constructor having the formal parameter
types supplied as parameterTypes , if any. |
Method Summary | |
---|---|
String |
toString()
Returns the string representation of this factory. |
Methods inherited from class dk.rode.thesis.meta.reflect.InstantiableTypeLiteral |
---|
create, create, create, equals, getConstructor, isInstatiable, isInstatiable, newInstance |
Methods inherited from class dk.rode.thesis.meta.reflect.TypeLiteral |
---|
asClass, asClass, asType, create, create, create, getComponentType, getRawType, getRawType, getType, hashCode |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected Factory(Class<?>... parameterTypes) throws NoSuchMethodException
T
using
the declared constructor having the formal parameter
types supplied as parameterTypes
, if any.
The constructor is made accessible if not already. New instances
of T
must be created with the InstantiableTypeLiteral.newInstance(Object...)
factory method.
parameterTypes
- The formal parameter types for the
declared constructor to use.
IllegalArgumentException
- If this class is not generic, if
T
has no raw type, or if the raw raw represents
a non instantiable class.
NoSuchMethodException
- If no such constructor is declared in
the raw type of T
.Method Detail |
---|
public String toString()
toString
in class TypeLiteral<T>
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |