Intent - Define an interface for creating an
object, but let subclasses decide which class to
instantiate. Defers intantiation to subclasses.
Problem -
A class needs to instantiate a derivation of another
class, but doesn't know which one.
A class wants its subclasses to specify the objects
it creates
Solution - A derived class makes the decision on
which class to instantiate and how to instatiate it.
Participants and Collaborators
Product
ConcreteProduct
Creator
ConcreteCreator
Consequences
Clients might need to subclass the Creator class
just to make a particular ConcreteProduct
Factory methods eliminate the need to bind
application-specific classes into your code. You only
deal with generic Product interfaces, allowing
ConcreteProducts to be interchanged easily.
Provides hooks for subclasses
Connects parallel class heirarchies
Implementation
Two types: abstract Factory method, or a concrete
Factory method with default implementation
Parameterized factory methods: can create multiple
product types from one method
The Factory Method allows the creators to be more than just
creators for products, they might create a structure using the
products created from their factory methods.