[title]Saving Application Settings to Flash[/title]
[01/02/2012 - Modified]
I moved the “serialization” from GetSettings to the base class SaveToFlash, which will allow different methods of serialization in the future without changing all derived classes.
FlashSettings is an abstract base class that provides methods for saving and loading application settings to and from flash memory. The class is defined in such a way the it allows multiple levels of derived classes to save and restore their settings in a safe and consistent manor. Each derived class may override these methods:
InitSettings - to set initial values for their settings when the constructor is called. GetSettings - to retrieve the "serialized" values for their settings. SetSettings - to set their settings from "serialized" values. ValidateSettings - to validate their own settings before they are saved to flash memory.
The example project includes these two derived classes:
- AppSettings : DeviceSettings - DeviceSettings : FlashSettings
The example attempts to load settings from flash, and will fail the first time it is run.
It then tries to save invalid Device settings, invalid App settings, and then valid Device and App settings to demonstrate how validation works.