如何实现"类版本" (使用不同版本的同一类的) [英] How to implement "class versioning" (using different version of the same class)
问题描述
下面的问题是:我们的主类(比如:合同)每年都会发生改变。某些属性的添加,其他的都被删除。我们不知道它如何看明年。它可能会发生很大的变化,或根本没有。
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).
当然,我们必须能够读回...一个选项(残酷)是每年有一个新的合同类(Contract2008,Contract2009,...)。
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 ?
在此先感谢!
(我们使用C#2.0)。
(We're using C# 2.0.)
补充:谢谢你的答案。现在我们要求我们自己,我们如何使用字典/ XML文件来执行的版本没有打破所有code。字典看起来很性感在这方面:O)
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.
而不是编码领域的进级的;这听起来像你可能需要更多的字典排序结构,可以动态地拉基于存储一年数据库配置值的字段的。然后建立基于这些值的动态UI。其每年创建一个新类和测试code似乎不可能维持昂贵的。
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.
这篇关于如何实现"类版本" (使用不同版本的同一类的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!