-
Notifications
You must be signed in to change notification settings - Fork 1
/
2-7-proxy.vala
48 lines (38 loc) · 911 Bytes
/
2-7-proxy.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
interface Door : Object {
public abstract void open ();
public abstract void close ();
}
class LabDoor : Object, Door {
public void open () {
print ("Opening lab door\n");
}
public void close () {
print ("Closing the lab door\n");
}
}
class Security : Object {
protected Door door;
public Security (Door door) {
this.door = door;
}
public void open (string password) {
if (authenticate (password)) {
door.open ();
} else {
print ("Big no! It ain't passible.\n");
}
}
public bool authenticate (string password) {
return password == "$ecr@t";
}
public void close () {
door.close ();
}
}
public int main (string[] args) {
var door = new Security (new LabDoor ());
door.open ("invalid");
door.open ("$ecr@t");
door.close ();
return 0;
}