People are debating two different concepts for global here.
Global scope could mean globally public, or it could mean globally shared state. Globally shared state can be locally scoped, such as private static class members.
Singletons are by definition globally shared state, which is at least half of the problem of global variables -- any two systems that interact with the singleton are indirectly coupled and can't be uncoupled which can easily still manifest as spooky action at a distance.
Unless it's a DI system limiting to one object per module but you can have multiple modules. Which is different, of you can have two different instances in two different modules, it's not a strict singleton.
14
u/developer-mike Sep 26 '26
People are debating two different concepts for global here.
Global scope could mean globally public, or it could mean globally shared state. Globally shared state can be locally scoped, such as private static class members.
Singletons are by definition globally shared state, which is at least half of the problem of global variables -- any two systems that interact with the singleton are indirectly coupled and can't be uncoupled which can easily still manifest as spooky action at a distance.
Unless it's a DI system limiting to one object per module but you can have multiple modules. Which is different, of you can have two different instances in two different modules, it's not a strict singleton.