memento模式

 http://www.cnblogs.com/w0w0/archive/2012/05/21/2512153.html

http://www.cnblogs.com/mayvar/archive/2011/09/08/wanghonghua_201109080336.html

 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4 #include <cstdlib>
 5 #include <map>
 6 #include <list>
 7 #include <algorithm>
 8 #include <cstring>
 9 #include <string.h>
10 
11 using namespace std;
12 
13 class Memo;
14 
15 //发起人类
16 class Originator {
17 public:
18     string state;
19     Memo* CreateMemo();
20     void SetMemo(Memo* memo);
21     void Show() {
22         cout << "状态:" << state << endl;
23     }
24 };
25 
26 //备忘录类
27 class Memo {
28 public:
29     string state;
30     Memo(string strState) {
31         state = strState;
32     }
33 };
34 
35 Memo* Originator::CreateMemo() {
36     return new Memo(state);
37 }
38 
39 void Originator::SetMemo(Memo* memo) {
40     state = memo->state;
41 }
42 
43 //管理者类
44 class Caretaker {
45 public:
46     Memo* memo;
47 };
48 
49 
50 int main() {
51     Originator* on = new Originator();
52     on->state = "on";
53     on->Show();
54 
55     Caretaker* c = new Caretaker();
56     c->memo = on->CreateMemo();
57 
58     on->state = "off";
59     on->Show();
60 
61     on->SetMemo(c->memo);
62     on->Show();
63     return 0;
64 }
原文地址:https://www.cnblogs.com/kakamilan/p/2621807.html