forked from thuvu33/design_pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (63 loc) · 1.78 KB
/
Copy pathmain.cpp
File metadata and controls
76 lines (63 loc) · 1.78 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "IGroup.h"
#include "CodeGroup.h"
#include "PageGroup.h"
#include "RequirementGroup.h"
#include "Invoker.h"
#include "AddRequirementCommand.h"
#include "DeletePageCommand.h"
#include <iostream>
using namespace std;
void DoIt()
{
cout << "----------客户想增加一个需求----------" << endl;
IGroup *rg = new CRequirementGroup();
rg->Find();
rg->Add();
rg->Plan();
delete rg;
cout << endl;
cout << "----------客户又想修改一个页面----------" << endl;
IGroup *pg = new CPageGroup();
pg->Find();
pg->Add();
pg->Plan();
delete pg;
cout << endl;
cout << "----------客户又想删除一个功能----------" << endl;
IGroup *cg = new CCodeGroup();
cg->Find();
cg->Add();
cg->Plan();
delete cg;
cout << endl;
return;
}
void DoNew()
{
cout << "\n----------客户觉得烦了,希望只找一个人,并告诉他要做什么----------\n" << endl;
cout << "----------客户要求增加一项需求----------" << endl;
CInvoker gary;
ICommand *pcommand = new CAddRequirementCommand();
gary.SetCommand(pcommand);
gary.Action();
delete pcommand;
cout << endl;
//客户想要改动只需要找CInvoker就可以了。
cout << "----------客户要求删除一个页面----------" << endl;
CInvoker ricky;
ICommand *pcommand2 = new CDeletePageCommand();
ricky.SetCommand(pcommand2);
ricky.Action();
delete pcommand2;
cout << endl;
return;
}
int main(int argc, char* argv[])
{
//客户原来的运行流程
DoIt();
//客户觉得麻烦了,每次改动都要找不同的组,谈不同的事
//客户只想找一个人,告诉他要做什么就可以,不想关心由哪几个组来做和怎么做
DoNew();
return 0;
}