-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDecorator.cpp
78 lines (62 loc) · 1.5 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
//g++ Decorator.cpp -Wc++11-extensions -std=c++11
#include <string>
#include <iostream>
#include <memory>
class Person{
public:
std::string _name;
Person(){}
Person(std::string &&name){
//std::cout<<"call move Person"<<std::endl;
_name = name;
}
Person(Person &&component){
this->_name = std::move(component._name);
}
// Person& operator= (Person &&component){
// std::cout<<"call move operator ="<<std::endl;
// this->_name = std::move(component._name);
// return *this;
// }
virtual void Show(){
std::cout<<"decorate for "<<_name<<std::endl;
}
};
class Finery:public Person{
public:
Finery(){}
void Decorate(const std::shared_ptr<Person> &person){
this->_person = person;
}
void Show(){
_person->Show();
}
private:
std::shared_ptr<Person> _person;
};
class TShirts:public Finery{
public:
TShirts(){}
void Show(){
std::cout<<"T Shirts ";
Finery::Show();
}
};
class BigTrouser:public Finery{
public:
BigTrouser(){}
void Show(){
std::cout<<"Big Trousers ";
Finery::Show();
}
};
int main(){
std::string name("Simon");
std::shared_ptr<Person> xc = std::make_shared<Person>(std::move(name));
std::shared_ptr<Finery> bt = std::make_shared<BigTrouser>();
std::shared_ptr<Finery> ts = std::make_shared<TShirts>();
ts->Decorate(xc);
bt->Decorate(ts);
bt->Show();
return 0;
}