What is factory method ?
The factory pattern method defines an interface for creating an object,but lets subclasses decide which class to instantiate.
!!! Use of factory method gives programmer oppertunity to abstract the specific attributes of an object into specific subclasses which create them.
The following diagram show the structure of the factory method.
Structure

Paticipant of the Factory Method
Product
The product define the interface of type of object which factory method creates.
Concrete Product
Implement the product interface
Creator
It define the factory method.Its class that contains the implementation for all of the methods to manipulate products.
Concrete Creator
Override the factory method to return an instance of a ConcreteProduct.It responsible for creates one or more concrete products.It has knowledge how to create these products.
What i learnt about Factory Pattern
- Allow subclasses to choose which type of object to create.
- Factory method make code more flexible and extensible,because it allows to program and design interface not implimentation in changing code.
- It avoid duplication of code and provide one place to perform maintanance ,by placing all creation code in one object or method.
Related Pattern
Abstract Factory-
Factory method is useful for impliment individual object for specific purpose without the developer knowing class being instantiated.The Abstract factory is usefull when someone need to create a matched set of bjects rather than individual object.
Prototype-The prototype pattern provides an alternative way for an object to work wtih other object.
References
Head first Design patterns/Eric Freeman & Elisabath Freeman
ISBN-0-596-00712-4
Tar bob/Factory patterns ,Factory method, and Abstract Factory,
http://www.research.umbc.edu/~tarr/dp/lectures/Factory.pdf