Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern for storing settings in c#

I have the following application which interfaces with a custom device. The application is used to program the device.

My application can read settings from the device, and program settings to the device. So that would mean, two sets of settings; one set of settings which are currently in the device, and one which are entered by the user via the application.

There are differnt device types, all with some settings in common and some device specific.

I was thinking about two classes, with both the complete set of settings. Both using singleton so I can easily acces all setting through my whole project. But this does not feel right, any tips on this situation

like image 292
2pietjuh2 Avatar asked Nov 03 '22 10:11

2pietjuh2


1 Answers

Not a design pattern but I'd probably do this:

// represents a device with it's settings
public class Device
{
   public string Type { get; set;}

   public List<Setting> Settings { get; set; }
}

// represents a setting, agnostic of which device it applies to
public class Setting
{
   public string Setting { get; set; }

   public string Value { get; set; }
}

// represents mapping which devices has which settings
public class DeviceSettings
{
   public List<string> ApplicableDevices { get; set; }

   public List<Settings> ApplicableSettings { get; set; }
}

Don't focus on the collection types used. And I would imagine you would have more properties.

Using this design, you can define settings at run time and assign them to particular devices.

like image 128
rro Avatar answered Nov 13 '22 17:11

rro