Singleton is a simple object-oriented design pattern where a class only gets to have one single instance at any given time while providing a global point of access.
- Ensures that only one instance of class is exists at a given time.
- Provides a global point of access to the instance.
Here is how you create a singleton:
After doing this all you need to do is:
Using singleton is especially useful when handling single resources such as loggers, configurations etc.