What is Factory Design Pattern?

 Posted by Rajnilari2015 on 12/19/2015 | Category: Design Pattern & Practices Interview questions | Views: 1840 | Points: 40

Factory pattern comes under the category of Creational Pattern that promises the best way to create objects.
If we need the creation of many different types of objects when all derived from a common base type, Factory Pattern is the choice. Factory pattern does this by the help of Factory Method.It defines a method for creation of objects to sub classes.This means that a base class(abstract class) or interface is defined and subclasses which implement the interface / abstract class , are left to object instantiation. However, client code doesn't create an object against this interface. At run time, the Factory Method accepts a desired object as a parameter and returns a base class pointer to a new instance of that object.This pattern works best when a well-designed interface is used for the base class, so there is no need to cast the returned object.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response