Class/Object basics..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Lister

    #1

    Class/Object basics..

    I'd like to have an XML document that my app reads and writes to on a
    regular basis. It will read the XML document on opening, write to it when
    closing, and while running, it will do updates and add and delete nodes.

    So...

    I think I should create a 'Settings' class, with methods for reading,
    writing, getting a value.. etc..

    So, my question is: Where would I declare the object. Or should I say,
    create it, so that I have access to it from anywhere in my main class? So
    that at any point, I can say:

    SettingsObject. Flush(); // Update the settings file with the latest changes
    SettingsObject. ShutDown() // Do all the end-of-running things, and close the
    XML file.


  • Bruce Wood

    #2
    Re: Class/Object basics..

    I would make it a Singleton. Look up the Singleton design pattern. Jon
    Skeet has a page on this:



    Your "Settings" class could use composition: it could contain an XML
    document as a private field, and then provide a "nice" interface to the
    rest of the application that talks to the app in higher-level terms (so
    that the app doesn't have to know that the settings are stored in XML,
    and you could change the representation / location of the settings
    later).

    Comment

    Working...