Skip to content

Latest commit

 

History

History
15 lines (8 loc) · 976 Bytes

README.md

File metadata and controls

15 lines (8 loc) · 976 Bytes

Singleton Pattern

Guarantee that there is only one instance of the singleton object within an application.

This pattern is commonly used to ensure that only one instance of the particular object exists in memory. This is particularly useful for objects that coordinate access to shared resources such as data stores.

Disadvantages

Despite being one of the most frequently used design patterns, Singleton presents some disadvantages.

Testing

Singletons can make unit testing harder. Classes that depend on a Singleton are very hard to isolate: this means that when testing a class that depends on a Singleton, it's easy to end up testing the Singleton as well. More on this can be found in this talk by Miško HeveryThe Clean Code Talks - Global State and Singletons

For more information, Wikipedia provides a great overview of the pattern: Wikipedia Article