“GLOBAL STATE!” Keep in mind that global state is transitive, so any object which is reachable from a global variable is global as well. It is not possible to have a Singleton and not have a global state.
Use singleton where all of the reachable objects are immutable
Global state is harmful to the application. If all objects are immutable than Singleton has no global state, as everything is constant.
Use singleton for logging
- It is acceptable because your application does not behave any different whether or not a given logger is enabled.
- The information here flows one way: From your application into the logger.
- Even thought loggers are global state since no information flows from loggers into your application, loggers are acceptable.
Leave a Reply