Programming in Windows with Visual Studio 2010 C++ and MFC.  My question is about how best to store, update, and pass around program settings or options.I have a simple main GUI window/frame/dialog.  On that main window I have an options button.  When I click the options button I create an Options Dialog. Inside the options dialog I get a reference to the application (an MFC concept, globally available) and grab a reference to my custom settings class (an instance is stored in the application class.  From there, I can populate my options dialog and save my options back.Perhaps I should be using Dependency injection to inject the settings into my option dialog?  Or perhaps I should not even be accessing the settings from within the dialog class?  MaybeI should expose the settings via set/get on the dialog class?Also, now I want to show some options right there on the main window, while still keeping them settable on the original options dialog.  So now I'm wondering what a good design is for this.  If I set an option on my options dialog I want it to update the options displayed on the main window.I guess this is a good spot for the Observer pattern but I'm trying to figure out how to piece it altogether in a MFC context (which as best as I can tell is basically pretty much the same as any other GUI toolkit in any other language, so if you're not into MFC I still want your comments)How should I be passing my settings around? How do I keep the GUI display of the settings in sync with each other? Such that after clicking OK on the options dialog box, the options directly shown on the main window are updated?
GUI: Setting options in two different places and having them stay in sync?
c++;design patterns;gui;class design;mfc
Ok I have solved this problem using Dependency Injection and the Observer pattern.  To pass settings aroundI have a single Settings object that I instantiate in my MFC app object, MyApp (a subclass of CWinApp).  Previously I added a getter function call GetSettings() on my MyApp.  This allowed me to get the settings from any window class because there is member method ((MyApp*)AfxGetApp())->GetSettings().  This however suffers the problems of global state and making it non-obvious that a class utilizes the settings object.  Now instead I dependency inject my settings object into my CDialog class via the constructor.  Then I dependency inject it into my OptionsDialog class.  This takes care of passing the settings around.To keep GUI display of settings in syncI used the Observer pattern.  I created two abstract classes Subject and Observer as:#pragma once#include <list>class Observer;class Subject{public:    virtual ~Subject()  {}    virtual void AttachObserver(Observer *observer);    virtual void DetachObserver(Observer *observer);    virtual void NotifyObservers();protected:    Subject() {}private:    std::list<Observer *> observers_;};and:#pragma onceclass Subject;class Observer{public:    virtual ~Observer() {}    virtual void Update(Subject *subject) = 0;protected:    Observer() {}};Then I made my Settings class derive from Subject and called NotifyObservers() from my settings' class's Save() method.Finally I made my OptionDialogPanel on my main window derive from Observer.  In my OnInitDialog() I call settings_->AttachObserver(this) to register my option panel as a listener of my settings object.  Then I implemented the Update method to grab fresh settings from my settings object and put them in into the text boxes:void OptionsDialogPanel::Update(Subject *subject){    if(subject == settings_)    {        UpdateToCurrentSettings();    }}