-
Notifications
You must be signed in to change notification settings - Fork 78
/
TemplateMethod.cpp
60 lines (52 loc) · 1.08 KB
/
TemplateMethod.cpp
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
#include<iostream>
class CoffeeMaker
{
public:
// 자식 클래스에서 공통으로 사용하는 TEMPLATE METHOD
void makeCoffee()
{
boilWater();
putEspresso();
putIce();
putExtra();
}
// HOOK METHOD
virtual void putExtra() = 0;
void boilWater()
{
std::cout << "물을 끓인다" << std::endl;
}
void putEspresso()
{
std::cout << "에스프레소를 넣는다." << std::endl;
}
void putIce()
{
std::cout << "얼음을 넣는다." << std::endl;
}
};
class LatteMaker : public CoffeeMaker
{
public:
void putExtra() override
{
std::cout << "우유를 넣는다." << std::endl;
}
};
class AmericanoMaker : public CoffeeMaker
{
public:
void putExtra() override
{
std::cout << "시럽을 넣는다." << std::endl;
}
};
int main()
{
CoffeeMaker* latteMaker = new LatteMaker();
latteMaker->makeCoffee();
std::cout << std::endl;
CoffeeMaker* americanoMaker = new AmericanoMaker();
americanoMaker->makeCoffee();
return 0;
}