纪元模式与序列化之间的差异 [英] Difference between Memento Pattern and Serialization
问题描述
从我可以收集的两者都可以用来存储对象,并有他们以后再带回来,但是我还没有找到一个明确的答案,他们之间的关键区别是什么,也许我错过了我的研究中的一些东西,但我想知道是否有人可以揭示什么差异在这两个之间。
谢谢
用于实现回滚/保存点支持。例如,我可能想要在某个时间点标记一个对象的状态,做一些工作,然后决定将该对象还原到标记的位置。
实现一个Memento模式可以使用序列化,这将包括将对象的内容保存为一个字节[]并保留在内存中或写入磁盘。当返回对象的内容将从序列化的副本重建时。
相反,我可以通过在内存中克隆对象并保留对副本的引用来实现Memento模式然后如果对象需要还原,则将状态复制回来。此方法不使用序列化。
I am doing some research into the Memento Pattern and I am generally new to behavioural patterns and with my research I have been getting pretty confused. One of the main things I have been getting confused on is the differences between the Memento Pattern and Serialization.
From what I can gather both can be used to store objects and have them brought back at a later date but I have not been able to find a clear cut answer on what the key differences between them are, maybe I have missed something in my research but I was wondering if anyone could shed some light on what the differences are between the two.
Thanks
Typically the Memento pattern is used to implement roll-back/save point support. For example I might want to mark the state of an object at a point in time, do some work and then decide to revert that object back to the point at which is was marked.
The implementation of a Memento pattern could use serialisation, which would involve saving the contents of the object into a byte[] and keeping in memory or writing to disk. When reverting the content of the object would be rebuilt from the serialised copy.
Conversely I could implement a Memento pattern by cloning the object in memory and keeping a reference to the copy and then copying the state back if the object needs reverting. This method doesn't use serialisation.
这篇关于纪元模式与序列化之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!