I've created a few classes as Controllers
for my routes in Node.js
and I'd like them to be able to work on a singleton basis (not required, it's an extra)
Main Controller class
class RouteController {
static getInstance() {
if (!RouteController.singleton) {
RouteController.singleton = new RouteController();
}
return RouteController.singleton;
}
}
Now I want to create a route for example viewing posts and I want that class to have the singleton pattern as well, but not cop
PostController class
class PostController extends RouteController {
}
If I do this and check it console.log(RouteController.getInstance() === PostController.getInstance())
it returns true
when I want each (sub)class to have their own singleton instance.
How can I do this correctly?
via CreasolDev
No comments:
Post a Comment