- Prototype pattern
- Regular Class
- Module pattern (Revealing Pattern).
We will discuss Prototype pattern in our subsequent video sessions, let’s discuss other two types here. In Regular Class we can write constructor function (Any function who gives us instance is known as constructor function), with this we can create Private function rather than exposing small functions, instead can expose API’s. But issue here is we end up creating new instances. What if we want to stop people from creating multiple instances?
So here comes the concept of Module Pattern which restricts people to create instances. Through module pattern we get many benefits like we can create private function, public function, it also guarantees we have one instance only and it is memory efficient as well.
Module pattern is heavily designed on closure principle; whoever is familiar with Closure concept can design this. This is very important designing pattern as it fulfills any kind of requirement which needs single instance. We can design very complicated objects like we can have private variables; private functions and has flexibility to expose whatever we want to. It is good for services and testing/TDD as well.