-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMain.cpp
More file actions
33 lines (25 loc) · 797 Bytes
/
Copy pathMain.cpp
File metadata and controls
33 lines (25 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/********************************************************************
created: 2006/08/09
filename: Main.cpp
author: 李创
http://www.cppblog.com/converse/
purpose: Memento模式的测试代码
*********************************************************************/
#include "Memento.h"
int main()
{
// 创建一个原发器
Originator* pOriginator = new Originator("old state");
pOriginator->PrintState();
// 创建一个备忘录存放这个原发器的状态
Memento *pMemento = pOriginator->CreateMemento();
// 更改原发器的状态
pOriginator->SetState("new state");
pOriginator->PrintState();
// 通过备忘录把原发器的状态还原到之前的状态
pOriginator->RestoreState(pMemento);
pOriginator->PrintState();
delete pOriginator;
delete pMemento;
return 0;
}