View Full Version : What is the best way to store global properties?

08-08-2009, 12:44 AM
I am working on a project that has a few different sections that could be enabled. These sections are labeled things like 'work', 'about', 'contact', etc. There would not be an option to be in two sections at once. I am looking for a way for any class in my application to tell which section is enabled at that present time. What is the best way to store a "currentSection" property where any class could read from it at any time?

Thanks for the help!

08-08-2009, 06:33 AM
Really depends on the scope of your problem. If it's static information, you could use a set of well-known constants that you expose, or configuration settings stored somewhere (text file, database, XML, etc).

If it's something that needs to be dynamically accessed and edited at runtime, then you might want to look at a Singleton pattern (http://en.wikipedia.org/wiki/Singleton_pattern) to enforce concurrency in a multi-threaded environment.

08-10-2009, 04:52 AM
Agree. If just static settings - a separate class with static constants. If dynamic - a singleton class with setters/getters, or just a class with static variables.

08-11-2009, 07:15 PM
Cool, I just set up a singleton class called "Globals" and it has a couple of properties I am using so far... I created a stageWidth and stageHeight property which the main client sets at the application start and on every resize. Other classes seem to be able to pull from that global setting pretty good, so it works! Thanks!

Flash Gordon
08-18-2009, 04:43 AM
Could also make a static function of your document class like Application.application in Flex. Treat your "scenes" as views to the application and get the needed data and pass it to your components.