正确实施纪念碑 [英] Correct implementation of Memento
问题描述
不一定是使用纪念品设计模式,看守者是否是发起人的总和? 。 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屋!