org.jplate.foundation.gof.factory
Interface ContextFactoryIfc<V,C>

Type Parameters:
V - The type of object to be created.
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:
java.io.Serializable
All Known Subinterfaces:
AttributeFactoryIfc<A,N>, MixedFactoryIfc<V,C>
All Known Implementing Classes:
AbstractContextFactory, DefaultAttributeFactory

public interface ContextFactoryIfc<V,C>
extends java.io.Serializable

A factory that defines creating objects based upon a context (a parameter that the resulting object needs in order to be created). This is a version of 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. This interface introduces a parameter that is used when creating the object entitled Context. Also, as a context 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 context factory for creating the person:

public final class Person
{
    private String _name;
    private int    _age;

    public Person ( final String name )
    {
        name = _name;
    }

    private Person ()
    {
    }

    public String getName () { return _name; }

    public int getAge () { return _age; }

    public void setAge ( final String age ) { _age = age; }
}

public final class PersonFactory implements ContextFactoryIfc <Person, String>
{
    public Person create ( String name )
    {
        return new Person ( name );
    }

    public void destroy ( Person object )
    {
    }
}
    
Essentially, to implement a context factory, do the following:
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/ContextFactoryIfc.java $
    


Method Summary
 V create(C context)
          Creates a new object.
 void destroy(V object)
          Destroys (or cleans up) object created by self.
 

Method Detail

create

V create(C context)
Creates a new object.

Parameters:
context - The data needed to create the return value.
Returns:
A newly created object.

destroy

void destroy(V object)
Destroys (or cleans up) object created by self.

Parameters:
object - The object to destroy/clean-up.