org.jplate.foundation.gof.factory
Interface MixedFactoryIfc<V,C>
- Type Parameters:
V
- The type of object to be created or destroyed.C
- The context in which V
will be created. Consider this
akin to a param or data needed in order to successfully create an
object.
- All Superinterfaces:
- ContextFactoryIfc<V,C>, FactoryIfc<V>, java.io.Serializable
public interface MixedFactoryIfc<V,C>
- extends java.io.Serializable, FactoryIfc<V>, ContextFactoryIfc<V,C>
A mixed factory that represents both a ContextFactoryIfc
as well as
a normal FactoryIfc
(on that simply creates objects with no context
invloved.
This factory defines the "Gang of Four" Factory pattern: "Define an
interface for creating an object, but let subclasses decide which class to
instantiate. Factory Method lets a class defer instantiation to subclasses,"
p107 Design Patterns - Elements of Reusable Object-Oriented Software.
Also, as a factory can create objects, it must too be able to clean up those
objects (via the destroy()
method).
The following example illustrates a trivial implementation of a person and
a factory for creating the person:
public final class Person
{
private String _name;
private int _age;
public Person ( final String name )
{
_name = name;
}
public Person ()
{
}
public String getName () { return _name; }
public void setName ( final String name ) { _name = name; }
public int getAge () { return _age; }
public void setAge ( final String age ) { _age = age; }
}
public final class PersonFactory implements MixedFactoryIfc <Person, String>
{
public Person create ()
{
return new Person ();
}
public Person create ( final String name )
{
return new Person ( name );
}
public void destroy ()
{
}
}
Essentially, to implement a factory, do the following:
-
Define the class who will be created (for instance
Person
above).
-
Create a factory class implementing
MixedFactoryIfc
and
provde the generic type for MixedFactoryIfc
(for instance
implements FactoryIfc <Person, String>
above).
Modifications:
$Date: 2008-12-02 12:32:45 -0500 (Tue, 02 Dec 2008) $
$Revision: 479 $
$Author: sfloess $
$HeadURL: https://jplate.svn.sourceforge.net/svnroot/jplate/trunk/src/dev/java/org/jplate/foundation/gof/factory/MixedFactoryIfc.java $