-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridge.ts
51 lines (41 loc) · 1.04 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
interface Color {
applyColor(): void;
}
class RedColor implements Color {
applyColor = (): void => {
console.log('Applying color red.');
};
}
class BlueColor implements Color {
applyColor = (): void => {
console.log('Applying color blue.');
};
}
abstract class Shape {
constructor(protected color: Color) {}
abstract applyShape(): void;
}
class CircleShape extends Shape {
constructor(_color: Color) {
super(_color);
}
applyShape = (): void => {
console.log('Apply circle.');
this.color.applyColor();
};
}
class SquareShape extends Shape {
constructor(_color: Color) {
super(_color);
}
applyShape = (): void => {
console.log('Apply square.');
this.color.applyColor();
};
}
const redCircle = new CircleShape(new RedColor());
const blueCircle = new CircleShape(new BlueColor());
const redSquare = new SquareShape(new RedColor());
const blueSquare = new SquareShape(new BlueColor());
redCircle.applyShape();
blueSquare.applyShape();