正确实施纪念碑 [英] Correct implementation of Memento

查看:85
本文介绍了正确实施纪念碑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

不一定是使用纪念品设计模式,看守者是否是发起人的总和? 。 Memento背后的主要目的是,可以以统一,透明的方式处理不同的Originators(获得Memento,以后将其传回恢复状态)。



聚合关系不一定会阻止。 Caretaker的不同实例可能是不同发起者的集合(虽然Caretaker的一个实例仅涉及Originator的一个实例),并且仍然可以获得透明状态恢复的好处。


With the memento design pattern, is it wrong to have the Caretaker as an aggregate of the Originator?

解决方案

Not necessarily. The main purpose behind Memento is that it is possible to deal with different Originators in uniform, transparent way (get Memento, pass it back later to restore state).

The aggregate relation doesn't necessarily prevent that. Different instances of Caretaker might be aggregates of different Originators (although one instance of Caretaker deals with only one instance of Originator) and still get the benefits of transparent state restoration.

这篇关于正确实施纪念碑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆