When to use the singleton pattern?
Use the Singleton pattern when a class in your program should have just a single instance available to all clients; for example, a single database object shared by different parts of the program. The Singleton pattern disables all other means of creating objects of a class except for the special creation method.
Is singleton design pattern a code smell?
There is a common opinion that the Singleton pattern is not recommended because it presents a code smell, but there are some cases where it fits perfectly. For example, some components have no reason to be instanced more than once in a project. Take a logger for example.
What is the singleton design pattern?
Singleton design pattern is a software design principle that is used to restrict the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. For example, if you are using a logger, that writes logs to a file, you can use a singleton class to create such a logger.