Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating an extensible properties class (OOP)
    text
    copied!<p>I have an application which supports multiple types and versions of some devices. It can connect to these devices and retrieve various information.</p> <p>Depending on the type of the device, I have (among other things) a class which can contain various properties. Some properties are common to all devices, some are unique to a particular device.</p> <p>This data is serialized to xml.</p> <p>What would be a preferred way to implement a class which would support future properties in future versions of these devices, as well as be backwards compatible with previous application versions?</p> <p>I can think of several ways, but I find none of them great:</p> <ul> <li>Use a collection of name-value pairs: <ul> <li><strong>pros</strong>: good backward compatibility (both xml and previous versions of my app) and extensibility,</li> <li><strong>cons</strong>: no type safety, no intellisense, requires implementation of custom xml serialization (to handle different <code>value</code> objects)</li> </ul></li> <li>Create derived properties class for each new device: <ul> <li><strong>pros</strong>: type safety</li> <li><strong>cons</strong>: have to use <code>XmlInclude</code> or custom serialization to deserialize derived classes, no backward compatibility with previous xml schema (although by implementing custom serialization I <em>could</em> skip unknown properties?), requires casting for accessing properties in derived classes.</li> </ul></li> <li>Another way to do it?</li> </ul> <p>I am using C#, by the way.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload