-
Notifications
You must be signed in to change notification settings - Fork 1
/
1-2-factory-method.vala
47 lines (38 loc) · 1.1 KB
/
1-2-factory-method.vala
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
interface Interviewer : Object {
public abstract void ask_questions ();
}
class Developer : Object, Interviewer {
public void ask_questions () {
print ("Asking questions about patterns!\n");
}
}
class CommunityExecutive : Object, Interviewer {
public void ask_questions () {
print ("Asking questions about community building.\n");
}
}
abstract class HiringManager {
// Factory Method
public abstract Interviewer make_interviewer ();
public void take_interview () {
var interviewer = this.make_interviewer ();
interviewer.ask_questions ();
}
}
class DevelopmentManager : HiringManager {
public override Interviewer make_interviewer () {
return new Developer ();
}
}
class MarktingManager : HiringManager {
public override Interviewer make_interviewer () {
return new CommunityExecutive ();
}
}
public int main (string[] args) {
var dev_manager = new DevelopmentManager ();
dev_manager.take_interview ();
var marketing_manager = new MarktingManager ();
marketing_manager.take_interview ();
return 0;
}