org.jplate.foundation.gof.factory
Interface FactoryIfc<V>

Type Parameters:
V - The type of object to be created or destroyed.
All Superinterfaces:
java.io.Serializable
All Known Subinterfaces:
CdvBuilderFactoryIfc<V>, CdvParserFactoryIfc<V>, ChainOfResponsibilityFactoryIfc<V>, CsvBuilderFactoryIfc<V>, CsvParserFactoryIfc<V>, FieldFactoryIfc, JavaccParserFactoryIfc<V>, JPlateBuilderFactoryIfc<V>, JPlateParserFactoryIfc<V>, KvpFactoryIfc<V>, KvpParserFactoryIfc<V>, ListFactoryIfc<V>, MapFactoryIfc<K,V>, MixedFactoryIfc<V,C>, NodeParserFactoryIfc<V>, RecordFactoryIfc, RepoFactoryIfc, TableFactoryIfc, TabularBuilderFactoryIfc<V>, TabularParserFactoryIfc<V>, TagContextFactoryIfc<TC>, TdvBuilderFactoryIfc<V>, TdvParserFactoryIfc<V>
All Known Implementing Classes:
AbstractFactory, DefaultChainOfResponsibilityFactory, DefaultFieldFactory, DefaultKvpFactory, DefaultKvpParserFactory, DefaultRecordFactory, DefaultRepoFactory, DefaultTableFactory, DefaultTagContextFactory, SynchronizedHashMapFactory, SynchronizedLinkedListFactory, UnsynchronizedHashMapFactory, UnsynchronizedLinkedListFactory

public interface FactoryIfc<V>
extends java.io.Serializable

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 ()
    {
    }

    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 FactoryIfc <Person>
{
    public Person create ()
    {
        return new Person ();
    }

    public void destroy ()
    {
    }
}
    
Essentially, to implement a 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/FactoryIfc.java $
    


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

Method Detail

create

V create()
Creates a new object.

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.