-
Notifications
You must be signed in to change notification settings - Fork 0
/
TvAdapter.java
82 lines (63 loc) · 1.46 KB
/
TvAdapter.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
package kb.design_patterns.adapter;
/* Common interface for all smart TV's */
interface SmartTv {
public void turnOn();
public void turnOff();
public void openMenu();
public void connectToWifi(String wifiName);
public void openYouTube();
}
/* A concrete adapter implementation */
class SamsungTvAdapter implements SmartTv {
private SamsumgTv tv;
public SamsungTvAdapter(SamsumgTv samsungTv) {
tv = samsungTv;
}
@Override
public void turnOn() {
tv.on();
}
@Override
public void turnOff() {
tv.off();
}
@Override
public void openMenu() {
tv.menu();
}
@Override
public void connectToWifi(String wifiName) {
tv.connectWifi(wifiName);
}
@Override
public void openYouTube() {
tv.openYouTubeApp();
}
}
/* A concrete adapter implementation */
class SonyTvAdapter implements SmartTv {
private SonyTv tv;
public SonyTvAdapter(SonyTv sonyTv) {
tv = sonyTv;
}
@Override
public void turnOn() {
tv.powerOn();
}
@Override
public void turnOff() {
tv.powerOff();
}
@Override
public void openMenu() {
tv.showMenu();
}
@Override
public void connectToWifi(String wifiName) {
tv.connectToWifiNetwork(wifiName);
}
@Override
public void openYouTube() {
throw new UnsupportedOperationException("YouTube App is not supported for Sony TV.");
}
}