-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbridge.ats
46 lines (39 loc) · 1.11 KB
/
bridge.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
import { Logger } from '../logger';
import { int, float } from '../lang';
//Refined Abstraction
export class CircleShape {
constructor(x:int, y:int, radius:float, drawingApi:DrawingAPI) {
this.x = x;
this.y = y;
this.radius = radius;
this.drawingApi = drawingApi;
}
//low-level i.e. Implementation specific
draw() {
this.drawingApi.drawCircle(this.x, this.y, this.radius);
}
//high-level i.e. Abstraction specific
scale(pct:float) {
this.radius *= pct;
}
}
export class DrawingAPI {
constructor() {
this.logger = new Logger();
}
drawCircle(x:int, y:int, radius:float) {
throw new Error("Abstract method!");
}
}
//ConcreteImplementor 1/2
export class DrawingAPI1 extends DrawingAPI {
drawCircle(x:int, y:int, radius:float) {
this.logger.log('API1.circle at ' + x + ':' + y + ' radius ' + radius);
}
}
// ConcreteImplementor 2/2
export class DrawingAPI2 extends DrawingAPI {
drawCircle(x:int, y:int, radius:float) {
this.logger.log('API2.circle at ' + x + ':' + y + ' radius ' + radius);
}
}