Factory Method Pattern

It is a factory of classes. when we have a super class and some subclasses and we have to return the object of one of the subclasses, we use a factory pattern.
Factory Method pattern recommends encapsulating the functionality required, to select and instantiate an appropriate class, inside a designated method referred to as a factory method.

One of the simplest ways of designing a factory method is to create an abstract class or an interface that just declares the factory method. Another strategy is to create a concrete creator class with default implementation for the factory method in it. Different subclasses of this concrete class can override the factory method to implement specialized class selection criteria.
Pay attention that the factory method returns the parent type.

factory.jpg
page_revision: 6, last_edited: 1211197017|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License