Factory Design Pattern Can Help!
While writing code, do you worry about repeated code, structuring and maintenance then I believe factory design patterns can help you.
Before understanding the factory design pattern, let’s understand what factory means. It’s a place where something is produced right!
Now let’s understand a little deeper, we see different types of factories around us which produce different types of products. Likewise, let’s take an example of a toy factory, which produces items like iron man and Thor. So I want bulk order of iron man. I can ask for it specifically. If I want to bulk order mixed toys, I only ask for one factory that produces them.
Similarly, we can create a factory in programming using a factory design pattern. In programming, instead of toys, we have objects. We can build and categorise object creation using factory design patterns and having toys as a parent class we can instantiate the iron man toy object or Thor toy object. I hope we have understood what is the objective of the factory design pattern.
Formally, a factory design pattern is a creational design pattern. In other words, it is used to create an object. Also, it hides the actual object creation from the developer. The factory design pattern is the best way to handle multiple types of object creation.
For the full article visit :
https://deepakatariya.com/factory-design-pattern-can-help/