-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuilder.cpp
80 lines (66 loc) · 1.51 KB
/
builder.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
#include <iostream>
#include <string>
#include <map>
#include <boost/shared_ptr.hpp>
using std::cout;
using std::endl;
using namespace std;
class food{
public:
void setMilk(string milk){
foods["milk"] = milk;
}
void setPlate(string plate){
foods["plate"] = plate;
}
void setMeal(string meal){
foods["meal"] = meal;
}
void getFoods(){
for(auto it = foods.begin();it != foods.end();it++)
{
cout<<it->first<<":"<<it->second<<endl;
}
}
private:
std::map<string,string> foods;
};
class builder{
public:
virtual void getMilk(string) = 0;
virtual void getPlate(string) = 0;
virtual void getMeal(string) = 0;
void printBuilder(){fo.getFoods();}
protected:
food fo;
};
class adultBuilder:public builder{
public:
void getMilk(string milk){fo.setMilk("adult "+milk);}
void getPlate(string plate){fo.setPlate("adult "+plate);}
void getMeal(string meal){fo.setMeal("adult "+meal);}
};
class childBuilder:public builder{
public:
void getMilk(string milk){fo.setMilk("child "+milk);}
void getPlate(string plate){fo.setPlate("child "+plate);}
void getMeal(string meal){fo.setMeal("child "+meal);}
};
class cook{
public:
void setBuilder(boost::shared_ptr<builder> b){_b = b;}
void construct(string plate,string milk,string meal){
_b->getMilk(milk);
_b->getPlate(plate);
_b->getMeal(meal);
}
private:
boost::shared_ptr<builder> _b;
};
int main(){
auto b = boost::shared_ptr<builder>(new adultBuilder());
cook c;
c.setBuilder(b);
c.construct("white plate", "fuck milk", "roat meal");
b->printBuilder();
}