|
|
|
|
|
by jqpabc123
1816 days ago
|
|
which are very similar to global variables, but the compiler doesn't know that they're global Since as you say, they are very similar, wouldn't it be reasonable to assume for access purposes that they are effectively global? |
|
EDIT: If you're not aware, the way this works is that you call myFunction(getTheSingleton());, where "getTheSingleton()" fetches the Singleton object. myFunction() has no way of "knowing" its actually interacting with the singleton. This is a useful pattern, because you can create unit-tests over the "global" variable by simply mocking out the Singleton for a mock object (or maybe an object with preset state for better unit testing). Among other benefits (but also similar downsides to using a global variable: difficult to reason because you have this "shared state" being used all over the place)