Factory

Factory is one of the most popular design pattern out there. It is used to simply creation of the objects of different classes that inherit from a common super-class (or interface X) depending on some condition.

The Recipe

In order to create a factory for a class X:

  1. Create an XFactory class
  2. Add an X createX(params...) method to it
  3. Depending on the value of the parameters create and return an object that is an instance of the appropriate subclass of X

Leave Comment

Your email address will not be published.

Please type the characters of this captcha image in the input box

Please type the characters of this captcha image in the input box