-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
TypeScript 5 Design Patterns and Best Practices - Second Edition
By :
The Singleton pattern is a creational design pattern that ensures a class has only one instance and provides a global point of access to it. This pattern intends to control object creation and provide a single, shared instance of a class throughout the application. The term Singleton describes something that has only a single presence in the program. You use it when you want to get hold of a single object instead of many different ones for several reasons. Examples of this could be database connection objects or logging services that require a single point of access for all components in an application.
For example, you may want to keep only one instance of a particular class if it’s either expensive to create or if it doesn’t make sense to keep more than one for the lifetime of the program. Common use cases for the Singleton pattern include managing a database connection pool, managing a logging service, or managing a configuration object.
...