-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaceSegregationPrinciple.java
More file actions
60 lines (45 loc) · 1.15 KB
/
InterfaceSegregationPrinciple.java
File metadata and controls
60 lines (45 loc) · 1.15 KB
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
interface Device {
}
interface CallingDevice extends Device {
void call();
}
interface CameraDevice extends Device {
void takePhoto();
}
interface PrintingDevice extends Device {
void print();
}
class SmartPhone implements CallingDevice, CameraDevice {
@Override
public void call() {
System.out.println("SmartPhone is making a call");
}
@Override
public void takePhoto() {
System.out.println("SmartPhone is taking a photo");
}
}
class SmartWatch implements CallingDevice {
@Override
public void call() {
System.out.println("SmartWatch is making a call");
}
}
class Printer implements PrintingDevice {
@Override
public void print() {
System.out.println("Printer is printing a document");
}
}
class InterfaceSegregationPrinciple {
public static void main(String[] args) {
CallingDevice phone = new SmartPhone();
phone.call();
CameraDevice camera = new SmartPhone();
camera.takePhoto();
CallingDevice watch = new SmartWatch();
watch.call();
PrintingDevice printer = new Printer();
printer.print();
}
}