-
Notifications
You must be signed in to change notification settings - Fork 33
/
command.ats
55 lines (45 loc) · 1.07 KB
/
command.ats
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
import { Logger } from '../logger';
export class Command {
constructor(receiver:Receiver) {
this.logger = new Logger();
this.receiver = receiver;
}
execute() {
throw new Error("Abstract method!");
}
}
export class ConcreteCommand1 extends Command {
constructor(receiver:Receiver) {
super(receiver);
}
execute() {
this.logger.log("`execute` method of ConcreteCommand1 is being called!");
this.receiver.action();
}
}
export class ConcreteCommand2 extends Command {
constructor(receiver:Receiver) {
super(receiver);
}
execute() {
this.logger.log("`execute` method of ConcreteCommand2 is being called!");
this.receiver.action();
}
}
export class Invoker {
constructor() {
this.commands = [];
}
storeAndExecute(cmd:Command) {
this.commands.push(cmd);
cmd.execute();
}
}
export class Receiver {
constructor() {
this.logger = new Logger();
}
action() {
this.logger.log("action is being called!");
}
}