简体   繁体   English

处理版本控制的设计模式

[英]Design Patterns to Handle Versioning

I am building software which references a DLL containing ~10 classes each representing a message. 我正在构建引用DLL的软件,该DLL包含~10个类,每个类代表一条消息。 Each message contains fields that are specific to that message type. 每条消息都包含特定于该消息类型的字段。 Every six months or so updates are made to each message type and I am looking to make the software flexible enough to smoothly handle these transitions. 每六个月左右对每种消息类型进行更新,我希望软件足够灵活,以便顺利处理这些转换。 I would like to be able to select a version and a message type from a drop down menu in the GUI which would then reference the given version of that message type. 我希望能够从GUI中的下拉菜单中选择版本和消息类型,然后将引用该消息类型的给定版本。 I have a copy of the Gang of Four text and am trying to find a suitable solution to this task. 我有一份Gang of Four文本的副本,我正在尝试找到适合此任务的解决方案。 Any help would be much appreciated. 任何帮助将非常感激。

Yon can take a look at the Memento pattern . Yon可以看看Memento模式 It could help you the dropdown in your UI client. 它可以帮助您下​​载UI客户端。

to be able to select a version and a message type from a drop down menu in the GUI which would then reference the given version of that message type. 能够从GUI中的下拉菜单中选择版本和消息类型,然后将引用该消息类型的给定版本。

The last option can be the current .dll version. 最后一个选项可以是当前的.dll版本。 The Memento can be requested from the source object when it needs to checkpoint the source object's state. 当需要检查源对象的状态时,可以从源对象请求Memento。 The client is the "care-taker" of the Memento, but only the source object can store and retrieve information from the Memento (the Memento is "opaque" to the client and all other objects). 客户端是Memento的“照顾者”,但只有源对象可以存储和检索Memento中的信息(Memento对客户端和所有其他对象“不透明”)。 If the client subsequently needs to "rollback" the source object's state, it hands the Memento back to the source object for reinstatement. 如果客户端随后需要“回滚”源对象的状态,则将Memento交还给源对象以进行恢复。 It goes naturally with Command . 命令自然而然。

You can use command pattern for the rollback part as mentioned above. 如上所述,您可以将命令模式用于回滚部分。 Then you can use POJOs for the messages. 然后,您可以使用POJO作为消息。 Since the POJO features will change you can use Adapter or Decorator pattern to make the changes in the POJO, or you can directly change the POJO class, or you can extend the POJO classes into new POJO classes. 由于POJO功能将更改,您可以使用Adapter或Decorator模式在POJO中进行更改,或者您可以直接更改POJO类,或者您可以将POJO类扩展为新的POJO类。 And rest you can follow as mentioned by @ekostadinov. 休息你可以按照@ekostadinov的说法进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM