-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
63 lines (45 loc) · 1.04 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
class Circle {
private radius: number
public setRadius(radius: number): void {
this.radius = radius
}
public getRadius(): number {
return this.radius
}
}
class Square {
private area: number
public setArea(area: number): void {
this.area = area;
}
public getArea(): number {
return this.area
}
}
interface CircleToSquareAdapter {
converter(circle: Circle): Square
}
class AdapterCircleSquare implements CircleToSquareAdapter {
public circle: Circle
constructor(circle: Circle) {
this.circle = circle
}
converter() {
// fake implementaion for ilustration concent
const fakeResult = this.circle.getRadius() * 4
const square = new Square()
square.setArea(fakeResult)
return square
}
}
function clientCodeContext() {
const circle = new Circle()
circle.setRadius(5)
console.log('My Circle:', circle);
const adapter = new AdapterCircleSquare(circle)
const square = adapter.converter()
console.log('My square:', square);
}
export function adapter() {
clientCodeContext()
}