Singleton Pattern
Single object instance
GitHub code : https://github.com/FrancescoXX/Design-Patterns-Singleton-Javascript
Creational pattern
β‘οΈProblem (we need)
- One configuration file, from different components
- Always the same file
- Guaranteed that there is only one file
π‘Intent
- Ensure a class only has one instance.
- Provide a global point of access to it.
π§ Apply
- One instance of a class is required
- It must be one access point
- Need to manage object instances
β Pro
- Single point of access to the instance
- Avoid global variables
- Ability to subclass the singleton class
- Configure the number of instances
β οΈCons
- State of the singleton must be shareable between program executions
π Great for
- Manage number of instances at runtime
- Provide one single unique access
GitHub code : https://github.com/FrancescoXX/Design-Patterns-Singleton-Javascript
Top comments (0)