What is this factory all about and what are the advantages of using factory patterns? Does it give a plugable architecture? Why it is called "Factory"?
In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created.
The factory pattern aims to solve a fundamental problem in instantiation – i.e., the creation of a concrete object of a class – in object-oriented programming. In principle, creating an object directly within the class that needs or should use this object is possible, but very inflexible.
Why use a design pattern? The usefulness of using a design pattern is obvious. The design pattern can accelerate the development process. It provides proven development paradigms, which helps save time without having to reinvent patterns every time a problem arises.
It is factory since it is actually "Manufacturing" (Create) an object.
There's actually two kind of factory pattern defined by GoF:
Basically both of them tries to decouple the calling client from knowing the actual concrete implementation of the class/interface.
You can find all you need by reading this PDF article
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With