-
Notifications
You must be signed in to change notification settings - Fork 2
/
Command.ts
54 lines (40 loc) · 1.04 KB
/
Command.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
interface DoorCommand {
execute(): string;
}
class OpenCommand implements DoorCommand {
doors: string;
constructor(doors: string) {
this.doors = doors;
}
execute(): string {
return `Opened ${this.doors}`;
}
}
class CloseCommand implements DoorCommand {
doors: string;
constructor(doors: string) {
this.doors = doors;
}
execute(): string {
return `Closed ${this.doors}`;
}
}
class HAL9000DoorsOperations {
openCommand: DoorCommand;
closeCommand: DoorCommand;
constructor(doors: string) {
this.openCommand = new OpenCommand(doors);
this.closeCommand = new CloseCommand(doors);
}
close(): string {
return this.closeCommand.execute();
}
open(): string {
return this.openCommand.execute();
}
}
// USAGE:
const podBayDoors = "Pod Bay Doors";
const doorModule = new HAL9000DoorsOperations(podBayDoors);
console.log(doorModule.open()); //Opened Pod Bay Doors
console.log(doorModule.close()); //Closed Pod Bay Doors