-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathstrategy.ats
43 lines (33 loc) · 988 Bytes
/
strategy.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
import { Logger } from '../logger';
import { int, float } from '../lang';
export class Strategy {
constructor() {
this.logger = new Logger();
}
doOperation(num1:int, num2:int) {
throw new Error("Abstract method!");
}
}
export class Context {
constructor(strategy:Strategy) {
this.strategy = strategy;
}
executeStrategy(num1:int, num2:int) {
return this.strategy.doOperation(num1, num2);
}
}
export class OperationAdd extends Strategy {
doOperation(num1:int, num2:int) {
this.logger.log("add of operation" + ':' + (num1 + num2).toString());
}
}
export class OperationSubstract extends Strategy {
doOperation(num1:int, num2:int) {
this.logger.log('sub of operation' + ':' + (num1 - num2).toString());
}
}
export class OperationMultiply extends Strategy {
doOperation(num1:int, num2:int) {
this.logger.log('multiply of operation' + ':' + (num1 * num2).toString());
}
}