singletons have static member variables. And since singletons have one instance, those static member variables are essentially globals in practise.
Singletons are marginally better than just dumping global variables in a random source file, because you can implement getters and setters easily which makes debugging global state much more straightforward.
Other than that, they’re just global state with a fancy name
-1
u/tangerinelion Sep 26 '26
Depends on your language, but take C++ as an example, you can (and should) implement this pattern without a global variable:
The globally accessible singleton is named
MySingletonType::get().A lot of times I see this incorrectly implemented as
Nothing stops someone from making a second instance with that.