views:

29

answers:

2

If I have a setting that is accessible via a menu item or configuration window that can change at runtime, for example "bold text on/off"; what are some good ways of ensuring that all applicable components are aware the value of this setting?

A: 

You didn't provide specifics of an implementation language, so the asnwer will be somewhat generic. Assuming your GUI is in a language which supports even model (e.g. Java), simply have an event handler for any component which should be affected by settings and which gets triggered on an event "setting changed". Then call such event from the setting config window. Don't forget to redraw when all components are done updating (ore redraw as each component is updated).

An additional point is to hopefully have generic sub-components used. As an example, if you are using label text with a certain font which is configurable, then use a common "label with configurable font" class which ensures you never need to assign the above event listener to every label you create.

DVK
How would you control this listener registration, then? Would you have some EventHandlerService that is globally available that things would register with? It doesn't seem practical to pass a reference to this around to every component that might need it.
Markus Jevring
I'm severely tempted to state that the event handler service would be a static global object, but I'm almost certain there's a better pattern I'm just not remembering now.
DVK
A: 

If there will be a lot of setting I have implemented a sqlite DB to hold the changes for smaller amount of changes key value pair in a file is good enough. Then implement a observer design pattern so when any changes are done a list of gui classes are called to do the change.

Clutch
How would you manage the references with the observer? When components register as observers, what do they register with? Would you make this thing global or passed along to components. If you pass along, do you create all your components from the same place?
Markus Jevring