-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactory_method.cpp
More file actions
51 lines (42 loc) · 1.21 KB
/
Copy pathfactory_method.cpp
File metadata and controls
51 lines (42 loc) · 1.21 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
50
51
#include <iostream>
#include <memory>
class Interviewer {
public:
virtual void askQuestions(void) = 0;
};
class Developer : public Interviewer {
public:
void askQuestions(void) override {
std::cout << "Asking about design patterns!\n";
}
};
class CommunityExecutive : public Interviewer {
void askQuestions(void) override {
std::cout << "Asking about community building!\n";
}
};
class HiringManager {
protected:
virtual std::shared_ptr<Interviewer> makeInterviewer(void) = 0;
public:
void takeInterview(void) {
std::shared_ptr<Interviewer> interviewer = makeInterviewer();
interviewer->askQuestions();
}
};
class DevelopmentManager : public HiringManager {
std::shared_ptr<Interviewer> makeInterviewer(void) override {
return std::make_shared<Developer>();
}
};
class MarketingManager : public HiringManager {
std::shared_ptr<Interviewer> makeInterviewer(void) override {
return std::make_shared<CommunityExecutive>();
}
};
int main(void) {
auto devManager = DevelopmentManager();
devManager.takeInterview(); // Output: Asking about design patterns!
auto marketingManager = MarketingManager();
marketingManager.takeInterview(); // Output: Asking about community building!
}