-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface_Segregation_Principle.java
More file actions
109 lines (94 loc) · 2.83 KB
/
Interface_Segregation_Principle.java
File metadata and controls
109 lines (94 loc) · 2.83 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
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
/*
______________________________________________________________________________________________________________________________________________________
Title : Demonstrating the Single Responsibility Principle (SRP)
Student : Md. Farid Hossen Rehad
Computer Science & Engineering
Discipline
From Khulna University
_______________________________________________________________________________________________________________________________________________________
*/
/**
* Represents a device that can play media.
*/
interface MediaDevice {
/**
* Play media.
*/
void play();
/**
* Pause media.
*/
void pause();
/**
* Stop media.
*/
void stop();
}
/**
* Represents a device that can stream media.
*/
interface StreamingDevice {
/**
* Stream media.
*/
void stream();
/**
* Pause streaming.
*/
void pauseStreaming();
/**
* Stop streaming.
*/
void stopStreaming();
}
/**
* Represents a smart TV that can play and stream media.
*/
class SmartTV implements MediaDevice, StreamingDevice {
@Override
public void play() {
System.out.println("Playing media on Smart TV");
}
@Override
public void pause() {
System.out.println("Pausing media on Smart TV");
}
@Override
public void stop() {
System.out.println("Stopping media on Smart TV");
}
@Override
public void stream() {
System.out.println("Streaming media on Smart TV");
}
@Override
public void pauseStreaming() {
System.out.println("Pausing streaming on Smart TV");
}
@Override
public void stopStreaming() {
System.out.println("Stopping streaming on Smart TV");
}
}
/**
* Demonstrates the usage of a Smart TV that can play and stream media.
*/
class ISPExample {
public static void main(String[] args) {
// Create a Smart TV and test its media and streaming functionalities
SmartTV smartTV = new SmartTV();
smartTV.play();
smartTV.pause();
smartTV.stop();
smartTV.stream();
smartTV.pauseStreaming();
smartTV.stopStreaming();
}
}
/**
* In the above program, the MediaDevice interface represents the responsibility
* of playing, pausing, and stopping media, while the StreamingDevice interface
* represents the responsibility of streaming, pausing streaming, and stopping streaming.
* The SmartTV class implements both interfaces, adhering to the Interface Segregation
* Principle (ISP) by implementing only the methods relevant to its specific responsibilities.
*/