Intent:
Defines an interface for creating objects, but let subclasses to decide which class to instantiate
Refers to the newly created object through a common interface
Structure
Participant:
Factory provides a client with a common interface. The factorymethod returns a product, which may be used by factory's method, such as doSomething()
ConcreteFactory overrides the factorymethod in factory to create a concrete Product
Produt defines the interface for objects the factorymethod creates
ConcreteProduct: implements the Product interface
Collaboration
a Client requires Factory doSomething
a ConcreteFactory call its factorymethod to create a ConcreteProduct
the ConcreteFactory do something with the concrete product
Consequence:
Advantage:
The factorymethod separate the time to create an object and what to create, so the process to use the product can be reused and not changed by the change of product
Disadvantage:
The factorymethod pattern only provides clients a type of product at a time
Ref: http://www.oodesign.com/factory-method-pattern.html