-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBridge.java
More file actions
47 lines (38 loc) · 820 Bytes
/
Bridge.java
File metadata and controls
47 lines (38 loc) · 820 Bytes
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
interface DrawAPI {
void drawCircle(int x, int y, int radius);
}
class RedDraw implements DrawAPI {
void drawCircle(int x, int y, int radius) {
System.out.println("Red draw ");
}
}
class BlueDraw implements DrawAPI {
void drawCircle(int x, int y, int radius) {
System.out.println("Blue draw ");
}
}
class Shape {
DrawAPI drawApi;
public Shape (int x, int y, DrawAPI drawApi) {
this.drawApi = drawApi;
}
abstract void draw();
}
class Circle extends Shape {
int x, y, radius;
public Circle (int x, int y, int radius, DrawAPI drawApi) {
super(drawApi);
this.x = x;
this.y = y;
this.radius = radius;
}
public void draw() {
this.drawApi.drawCircle(x, y, radius);
}
}
class Test {
public static void main(String[] args) {
Shape c = new Circle(0, 1, 1, new RedDraw());
c.draw();
}
}