Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What is your approach with propagation to all classes/windows of preferences/settings of your application?

Do you share the preference_manager class to all classes/windows who need it or you make variables in each classes/windows and update them manually each time setting are changed?


Currently I have a PreferencesInterface class that hold all preferences and is responsible to default all values with a dedicated method called on create and when needed, all values are public, so non getters/setters, also it have virtual SavePreferences/LoadPreferences methods.

Then I have PreferencesManager that extends from PreferencesInterface and is responsible for actually implementation of SavePreferences/LoadPreferences. I've made this basically for cross-platform so that every platform can have a different implementation of actual storage (registry, ini, plist, xml, whatever).

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

It would be good having a Preferences class and a PreferenceManager class that extends/uses Preferences where the former will have getter methods for all preferences and the latter will add setters for the same. The former can be shared with all parts of the app that need access to preferences. The latter will be used only by the context(s) that can modify/has write access to the preferences.

share|improve this answer
add comment

Out of the options you give, I'd definitely side with the first.

Having a single class or object that is responsible for holding information about the users preferences, which is then queried by interested parties, is much more maintainable than having ever class that could be interested duplicating the storage of these settings and having to compile an ever-growing list of parties that need to be updated whenever something changes.

share|improve this answer
add comment

The only drawback of propagation of PreferencesManager that i see is that you can't really know that on a certain point that class is still exist (that the pointer in not simply pointing to a dirt memory), but the huge advantage is that settings are applied to all your application on-the-fly.

The other approach is more secure because you are really sure that variables are anytime accessible, but it's more triky to propagate changes.

I really don't know what's better...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.