Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a singleton to store global application parameters

Tags:

i'm developing a simple simulation with OpenGL and this simulation has some global constants that are changed by the user during the simulation execution. I would like to know if the Singleton design pattern is the best way to work as a temporary, execution time, "configuration repository"

like image 920
Lucas Avatar asked Feb 08 '10 18:02

Lucas


1 Answers

A singleton is probably the best option if you need to keep these settings truly "global".

However, for simulation purposes, I'd consider whether you can design your algorithms to pass a reference to a configuration instance, instead. This would make it much easier to store configurations per simulation, and eventually allow you to process multiple simulations with separate configurations concurrently, if requirements change.

Often, trying to avoid global state is a better, long term approach.

like image 90
Reed Copsey Avatar answered Nov 10 '22 14:11

Reed Copsey