In this post, Factory design pattern explained in simple and easy way.
Factory Design Pattern, one of the widely used Creation DP.
When it is suitable ?
Factory DP suitable when there is super class and many sub classes are maintained, based on the input sub classes need to be created dynamically.
What it does ?
 
Factory DP takes out the object creation responsibility from client program, and used Factory class for instantiation !!
How to make use of FactoryClass to construct object, is the next question
Example
 
Lets construct CakeFactory which instantiate cake based on user choice:
class CakeFactory {
          public Cake getCake ( int option ) {

                  Cake cake = null;
                  switch ( option ) {

                           case 1: 
                                    cake  = new BlackForest("Eggless");
                                    break;

                           case 2: 
                                    cake  = new Strawberry ("Egg");
                                    break;

                           case 3: 
                                    cake  = new BlackForest("Egg");
                                    break;

                   }  

                   return cake;                 
           }
}


Client code should be written similar as below:
Construct CakeFactory Object

CakeFactory cakeFactory = new CakeFactory  ();

For Eggless BlackForest, 

Cake bFelCake = cakeFactory .getCake(1);

 Similarly for Strawberry with Egg flavour,
 
Cake stEFCake = cakeFactory.getCake(2);

Thanks for reading post,  please comment for any questions or suggestions.