-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplate_with_Hook.cpp
More file actions
130 lines (102 loc) · 2.44 KB
/
Copy pathTemplate_with_Hook.cpp
File metadata and controls
130 lines (102 loc) · 2.44 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <string>
#include <algorithm>
#include <memory>
using namespace std;
class CaffeineBeverageWithHook
{
protected:
virtual void boilWater() const
{
cout<<"Boiling Water"<<endl;
}
virtual void pourInCup() const
{
cout<<"물에 붓는중"<<endl;
}
virtual bool customerWantsCondiments()
{
return true;
}
public:
virtual ~CaffeineBeverageWithHook()
{
cout<<"카페인 비버리지 소멸"<<endl;
}
virtual void prepareRecipe()
{
boilWater();
brew();
pourInCup();
if(customerWantsCondiments())
addCondiments();
}
virtual void brew() const = 0;
virtual void addCondiments() const = 0;
};
class TeaWithHook : public CaffeineBeverageWithHook
{
string getUserInput() const
{
cout<<"레몬을 넣어드릴까요? (y/n)"<<endl;
string k;
cin>>k;
transform(k.begin(), k.end(), k.begin(), ::tolower);
return k;
}
public:
void brew() const
{
cout<<"차를 우려내는중입니다"<<endl;
}
void addCondiments() const
{
cout<<"레몬을 넣는중입니다"<<endl;
}
bool customerWantsCondiments()
{
bool val =false;
string ans = getUserInput();
if(ans.find('y')!=ans.npos)
val = true;
return val;
}
};
class CoffeeWithHook : public CaffeineBeverageWithHook
{
string getUserInput() const
{
string k;
cout<<"설탕과 우유를 넣어드릴까요? (y/n)"<<endl;
cin>>k;
transform(k.begin(), k.end(), k.begin(), ::tolower);
return k;
}
public:
void brew() const
{
cout<<"커피를 필터를 통해 내리고있습니다"<<endl;
}
void addCondiments() const
{
cout<<"설탕과 우유를 넣어줍니다"<<endl;
}
bool customerWantsCondiments()
{
bool val = false;
string ans = getUserInput();
if(ans.find('y')!=ans.npos)
val =true;
return val;
}
};
int main()
{
unique_ptr<TeaWithHook> tea(new TeaWithHook());
unique_ptr<CoffeeWithHook> coffee(new CoffeeWithHook());
cout<<"차를 만듭니다"<<endl;
tea->prepareRecipe();
cout<<"커피를 만듭니다"<<endl;
coffee->prepareRecipe();
return 0;
}