-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBridge.ts
55 lines (46 loc) · 1.08 KB
/
Bridge.ts
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
class Commander {
executeObject: Executive;
constructor(executeObject: Executive) {
this.executeObject = executeObject;
}
order(): void {
this.executeObject.operate();
}
}
class AirForceCommander extends Commander {
order(): void {
console.log('Air Force commander make order')
// extra logics here
super.order();
}
}
class SpecialForceCommander extends Commander {
order(): void {
console.log('Special Force commander make order')
// extra logics here
super.order();
}
}
interface Executive {
operate(): void;
}
class Pilot implements Executive {
operate(): void {
console.log('Fly');
}
}
class Soldier implements Executive {
operate(): void {
console.log('Shoot');
}
}
// USAGE:
const commanderA = new AirForceCommander(new Pilot());
const commanderB = new SpecialForceCommander(new Soldier());
commanderA.order();
commanderB.order();
// OUTPUT:
// "Air Force commander make order"
// "Fly"
// "Special Force commander make order"
// "Shoot"