– Tutorial: “Factory Pattern Node.js Example”
Instead of using class constructors or
new keyword to create an object of a class, we can abstract this process. So, we can determine the type of object at run-time, by the time of generating that class object. The implementation seems like Factory Method, but simpler than Factory Method. This simple Factory is not treated as a standard GoF design pattern, but the approach is common to any place where we want to separate the code that varies a lot from the code that does not vary.
In this tutorial, I shows you how to do it in NodeJs.