-
Notifications
You must be signed in to change notification settings - Fork 1
/
1-3-abstract-factory.vala
75 lines (59 loc) · 1.66 KB
/
1-3-abstract-factory.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
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
interface Door : Object {
public abstract void get_description ();
}
class WoodenDoor : Object, Door {
public void get_description () {
print ("I'm a wooden door\n");
}
}
class IronDoor : Object, Door {
public void get_description () {
print ("I'm a iron door\n");
}
}
interface DoorFittingExpert : Object {
public abstract void get_description ();
}
class Welder : Object, DoorFittingExpert {
public void get_description () {
print ("I can only fit iron doors\n");
}
}
class Carpenter : Object, DoorFittingExpert {
public void get_description () {
print ("I can only fit wooden doors\n");
}
}
interface DoorFactory : Object {
public abstract Door make_door ();
public abstract DoorFittingExpert make_fitting_expert ();
}
class WoodenDoorFactory : Object, DoorFactory {
public Door make_door () {
return new WoodenDoor ();
}
public DoorFittingExpert make_fitting_expert () {
return new Carpenter ();
}
}
class IronDoorFactory : Object, DoorFactory {
public Door make_door () {
return new IronDoor ();
}
public DoorFittingExpert make_fitting_expert () {
return new Welder ();
}
}
public int main (string[] args) {
var wooden_factory = new WoodenDoorFactory ();
var door = wooden_factory.make_door ();
var expert = wooden_factory.make_fitting_expert ();
door.get_description ();
expert.get_description ();
var iron_factory = new IronDoorFactory ();
door = iron_factory.make_door ();
expert = iron_factory.make_fitting_expert ();
door.get_description ();
expert.get_description ();
return 0;
}