GoF Factory Method 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.

Componentized Factory Method Pattern

PerfectJPattern's version of the Factory Method Pattern only provides a supertype base interface. The common base Factory interface defines a common create() method. Possible parameters required by subtypes to create the specific instances may be added using Java Beans Setters. Providing parameters required for the creational code via Java Beans setters rather than via constructors makes instances of IFactoryMethod reusable.

UML Class Design



Example

import org.perfectjpattern.core.api.creational.factorymethod.*;
        
/**
 * Example of Factory Method subtype that creates Product with a
 * name parameter. 
 */
public 
interface IProductFactory
extends IFactoryMethod<Product>
{
    //------------------------------------------------------------------------
    // public
    //------------------------------------------------------------------------
    public void
    setName(String aName);          
}