Select from following answers:- Object creation happens through a single factory method for only one single item.
- It hides the construction of single object
- It exposes a method to the client for creating the object
- A factory class will have a factory method that returns a new instance of a class based on the parameter being passed.
- All Above

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.
Show Correct Answer
Asked In: Many Interviews |
Alert Moderator