-
Notifications
You must be signed in to change notification settings - Fork 1
/
bridge.java
112 lines (90 loc) · 2.06 KB
/
bridge.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
abstract class SoftwareImp {
abstract void app1Run();
abstract void app2Run();
abstract void app3Run();
}
class IOS extends SoftwareImp {
@Override
void app1Run() {
System.out.println("App1 run at IOS");
}
@Override
void app2Run() {
System.out.println("App2 run at IOS");
}
@Override
void app3Run() {
System.out.println("App3 run at IOS");
}
}
class Android extends SoftwareImp {
@Override
void app1Run() {
System.out.println("App1 run at Android");
}
@Override
void app2Run() {
System.out.println("App2 run at Android");
}
@Override
void app3Run() {
System.out.println("App3 run at Android");
}
}
abstract class PhoneBrand {
SoftwareImp softwareImp;
PhoneBrand(SoftwareImp softwareImp){
this.softwareImp = softwareImp;
}
public abstract void app1Run();
public abstract void app2Run();
public abstract void app3Run();
}
class Apple extends PhoneBrand{
Apple(SoftwareImp softwareImp) {
super(softwareImp);
}
@Override
public void app1Run() {
softwareImp.app1Run();
}
@Override
public void app2Run() {
softwareImp.app2Run();
}
@Override
public void app3Run() {
softwareImp.app3Run();
}
}
class Samsung extends PhoneBrand {
Samsung(SoftwareImp softwareImp) {
super(softwareImp);
}
@Override
public void app1Run() {
softwareImp.app1Run();
}
@Override
public void app2Run() {
softwareImp.app2Run();
}
@Override
public void app3Run() {
softwareImp.app3Run();
}
}
public class Main {
public static void main(String[] args) {
SoftwareImp impIOS = new IOS();
PhoneBrand apple = new Apple(impIOS);
apple.app1Run();
apple.app2Run();
apple.app3Run();
SoftwareImp impAndroid = new Android();
PhoneBrand samsung = new Samsung(impAndroid);
samsung.app1Run();
samsung.app2Run();
samsung.app3Run();
}
}