forked from yogykwan/design-patterns-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisitor.cc
More file actions
51 lines (39 loc) · 1.07 KB
/
visitor.cc
File metadata and controls
51 lines (39 loc) · 1.07 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
//
// Created by Jennica on 2017/1/3.
//
#include "visitor.h"
#include <iostream>
void Man::Accept(Action *action) {
action->GetManConclusion(this);
}
void Woman::Accept(Action *action) {
action->GetWomanConclusion(this);
}
void ObjectStructure::Attach(Person *person) {
people.push_back(person);
}
void ObjectStructure::Detach(Person *person) {
for(std::vector <Person*>::iterator it = people.begin(); it != people.end(); ++it) {
if(*it == person) {
people.erase(it);
return;
}
}
}
void ObjectStructure::Display(Action *action) {
for (std::vector<Person *>::iterator it = people.begin(); it != people.end(); ++it) {
(*it)->Accept(action);
}
}
void Success::GetManConclusion(Person *person) {
std::cout << "man gets success" << std::endl;
}
void Success::GetWomanConclusion(Person *person) {
std::cout << "woman gets success" << std::endl;
}
void Failure::GetManConclusion(Person *person) {
std::cout << "man gets failure" << std::endl;
}
void Failure::GetWomanConclusion(Person *person) {
std::cout << "woman gets failure" << std::endl;
}