where design pattern factory is used
where design pattern factory is used
The Factory Method pattern is generally used in the following situations: A class cannot anticipate the type of objects it needs to create beforehand. A class requires its subclasses to specify the objects it creates. You want to localize the logic to instantiate a complex object.
The factory design pattern is used when we have a superclass with multiple sub-classes and based on input, we need to return one of the sub-class. This pattern takes out the responsibility of the instantiation of a class from the client program to the factory class.
The Factory Method design pattern is used by first defining a separate operation, a factory method, for creating an object, and then using this factory method by calling it to create the object. This enables writing of subclasses that decide how a parent object is created and what type of objects the parent contains.
factory design pattern
Factory pattern
- a DP (design pattern) that may be the chosen solution approach by an app architect.
- there are factory functions and there are factory classes.
- - A factory class could be used to return a customized object (based on args)
In terms of code readability, factory pattern reveals the exact nature of the new object
we are creating. Also using this DP makes it easier to organize back-end development.
|