java - If Singletons are bad then how do you store global state for a framework -


if singletons considered bad global state, particularly state can affects main execution of code, how should global state for, say, web framework handled?

the immediate things come mind are:

  • base url
  • base file path
  • general configs
  • logging instance
  • etc

i cant see other way singleton access these such app() class or similar?

load data in place global application. instance, in web applications, can store data in application scope i.e. servletcontext using servletcontextlistener.

also, can use framework handles global state per context spring.

by way, there cases logging instances (i.e. logger logger) aren't stored in singleton instances in each class, marked static final.

more info related long-never-endind discussion singleton pattern usage:


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -