Factory design pattern

Factory design comes under creational design pattern. Its allows to create an instance based on input.

What is factory design pattern

Factory design pattern hide the object creation logic to client and object is created in a common place.

When to use factory design pattern

Concrete products to be created are unknown or are not defined in advance benefits from the alternative approach. Do you have multiple derived class and client request only on at a time based on condition?.

Advantage

  1. Modular expandability of the application
  2. Good testability
  3. Significant method names,
  4. Remove duplicate object creational logic
  5. less maintenance cost
  6. client doesn't worry about object creation.

Disadvantage

1.High number of required classes 2.Extension of the application is very elaborate