-
Notifications
You must be signed in to change notification settings - Fork 0
ApplicationController should be a singleton service #83
Copy link
Copy link
Open
Labels
Description
Anywhere we need a reference to the app controller, we create a new instance of one, e.g.
const appController = new ApplicationController();However, under the covers, it actually behaves like a singleton object. For example:
const appController1 = new ApplicationController();
const appController2 = new ApplicationController();
console.log(appController1 === appController2); // true(it does this by storing a reference to itself in the private static singletonInstance property, and the constructor returns this reference on the second and any subsequent calls)
Given this, and the fact that the *Controller naming convention is intended for 'view controllers' (i.e. classes that extend ViewController), it would be more appropriate to:
- Rename the class from
ApplicationControllertoApplicationService - Move it from
/controllers/application-controller.tsto/services/application-service.ts - Remove the constructor (and move anything there into
start()) - Make all instance properties & methods static
- Remove all local references to
ApplicationControllerinstances in other classes, and simply referenceApplicationControlleras a static singleton service.
Reactions are currently unavailable