Here is the problem : our main class (say : Contract) change every year. Some properties are added, other are removed. We don’t know how it will look next year. It may change a lot or not at all.
On the other hand, we now (new requirement…) have to keep an historic of every contracts. Each time the user update a contract, the whole object must be stored in a backup (e.g. – serialized in a table).
Of course, we must be able to read it back… One option (brutal) is to have a new Contract class every year (Contract2008, Contract2009, …).
But it would be very cumbersome (and ugly) since a lot of classes depend on Contract – in facts, we would have to create a bunch of new classes every year.
Ever have this kind of problem ? Any suggestion ?
Thanks in advance !
(We’re using C# 2.0.)
ADDED : Thank for your answers. We’re now asking ourself how we could use a dictionary / an XML file to implement versioning without breaking all the code. Dictionary seems very sexy in this context :o)
Stop serializing the object. Store the data relationally. Serialization is intended for short durations, say like streaming across the wire; not permanent storage.
Instead of coding the fields into the class; it sounds like you might need more of dictionary sort of structure that can dynamically pull fields based on database configuration values stored by year. Then build a dynamic UI based on those values. Having to create a new class each year and test the code seems impossibly expensive to maintain.