Using a singlet to store global application settings

I am developing a simple simulation with OpenGL, and this simulation has some global constants that the user changes while the simulation is running. I would like to know if the Singleton design template is the best way to work as a temporary, runtime, "configuration repository"

+5
source share
2 answers

Singleton is probably the best option if you want these settings to be truly global.

However, for the purpose of simulation, I would think if you can pass a link to a configuration instance instead of your algorithms. This would make it easier to save configurations for simulation and, ultimately, would allow multiple simulations to be processed simultaneously with separate configurations if requirements change.

Often, trying to avoid a global state is the best, long-term approach.

+4
source

I think in the past I used namespaces for this purpose, not singleton classes, but this should work (maybe even better).

, , ( XML YAML CSV ), , "config" ( - ).

+1

All Articles