-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecorator.cpp
96 lines (82 loc) · 1.93 KB
/
Decorator.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
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
#include<iostream>
#include<memory>
#include<string>
class Pizza
{
public:
virtual std::string getDescription() = 0;
virtual double getCost() = 0;
};
class PlainPizza : public Pizza
{
std::string getDescription() override
{
return "얇은 도우";
}
double getCost() override
{
return 4.00;
}
};
class ToppingDecorator : public Pizza
{
public:
Pizza* tempPizza;
ToppingDecorator(Pizza* newPizza)
{
tempPizza = newPizza;
}
std::string getDescription() override
{
return tempPizza->getDescription();
}
double getCost() override
{
return tempPizza->getCost();
}
};
class Mozzarella : public ToppingDecorator
{
public:
Mozzarella(Pizza* newPizza) : ToppingDecorator(newPizza)
{
std::cout << "도우 추가" << std::endl;
std::cout << "모짜렐라 치즈 추가" << std::endl;
}
std::string getDescription() override
{
return tempPizza->getDescription() + ", 모짜렐라 치즈";
}
double getCost() override
{
return tempPizza->getCost() + .50;
}
};
class TomatoSauce : public ToppingDecorator
{
public:
TomatoSauce(Pizza* newPizza) : ToppingDecorator(newPizza)
{
std::cout << "토마토 소스 추가" << std::endl;
}
std::string getDescription() override
{
return tempPizza->getDescription() + ", 토마토 소스";
}
double getCost() override
{
return tempPizza->getCost() + .35;
}
};
int main()
{
auto basicPizza = std::unique_ptr<Pizza>(new TomatoSauce(new Mozzarella(new PlainPizza)));
std::cout << "재료 : " << basicPizza->getDescription() << std::endl;
std::cout << "가격 : " << basicPizza->getCost() << std::endl;
// 도우 추가
// 모짜렐라 치즈 추가
// 토마토 소스 추가
// 재료 : 얇은 도우, 모짜렐라 치즈, 토마토 소스
// 가격 : 4.85
return 0;
}