- Forward


The FactoryMethod Pattern
An Introduction with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Overview
Back SMYC Forward
  • The "Problem":
    • Constructors are inflexible
  • Examples:
    • A limit on the number of instances
    • Initialization can't be completed
    • Objects may reside on multiple machines
    • Objects are expensive to construct
A Model
Back SMYC Forward
factorymethod
A Generic Example
Back SMYC Forward
factorymethod_pooled
A Specific Example
Back SMYC Forward

The Class to be Constructed

javaexamples/factorymethod/DirectoryListing.java
 
An Example (cont.)
Back SMYC Forward

The Factory

javaexamples/factorymethod/DirectoryListingFactory.java
 
There's Always More to Learn
Back -