Reputation: 3339
I'm developing a Java library that can be used within Android, Web and Desktop apps. The library consists of a few mostly separated modules that share common configuration settings (e.g. 'enabled', 'api key').
The Goal
The config should allow changes at runtime (e.g. API, JMX or SharedPreferemes in Android) without compromising portability (e.g. no database), testability or thread-safety (some modules run in a separate thread).
Approach
What I am currently using is a config object that I create at startup and pass to the various modules (which themselves pass it to sub classes). Each class then copies the fields it needs to a local field - the only problem: Settings cannot be changed at runtime.
Other ideas:
What's the best solution / best practice here?
UPDATE: Just to be clear, a module does not need to know if a change was made to the config, it should simply use the field's new value directly and work with it from then on.
Upvotes: 1
Views: 471
Reputation: 236004
Some suggestions:
Upvotes: 1