-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterfaceSegregationPrinciple.java
118 lines (101 loc) · 2.36 KB
/
InterfaceSegregationPrinciple.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
113
114
115
116
117
package solidDemo;
/*interface Uber {
int trackDistance(int x,int y);(let x,y be co-ordinates)
void getOTP();
void CabDetails();
void rating();
}
class Driver implements Uber {
@Override
public int trackDistance(int x,int y) {
return Math.abs(x-y);
}
@Override
public void getOTP() {
System.out.println(Math.random());
}
@Override
public void CabDetails() {
// doesn't require this method
}
@Override
public void rating {
// doesn't require this method
}
}
class User implements Uber {
@Override
public int trackDistance(int x,int y) {
return Math.abs(x-y);
}
@Override
public void getOTP() {
System.out.println(Math.random());
}
@Override
public void CabDetails() {
System.out.println("Name of the driver: Md Sameer");
System.out.println("Name of the car: Audi S9");
System.out.println("Car Number: AP 29 EX 1920");
}
@Override
public void rating {
System.out.println(3);
}
}*/
interface DriverHelper
{
int trackDistance(int x,int y);//(let x,y be co-ordinates)
void getOTP();
}
interface UserHelper {
void cabDetails();
void rating();
}
class Driver implements DriverHelper {
@Override
public int trackDistance(int x,int y) {
return Math.abs(x-y);
}
@Override
public void getOTP() {
int number = (int)(Math. random() * 10000);
System.out.println("Driver OTP "+number);
}
}
class User implements DriverHelper,UserHelper {
@Override
public int trackDistance(int x,int y) {
return Math.abs(x-y);
}
@Override
public void getOTP() {
int number = (int)(Math. random() * 10000);
System.out.println("User OTP "+number);
}
@Override
public void cabDetails() {
System.out.println("Name of the driver: Md Sameer");
System.out.println("Name of the car: Audi S9");
System.out.println("Car Number: AP 29 EX 1920");
}
@Override
public void rating() {
System.out.println("Rating :"+ 4);
}
}
public class InterfaceSegregationPrinciple {
public static void main(String[] args) {
Driver d = new Driver();
System.out.println("In view of the driver");
User u = new User();
System.out.println("The distance between user and driver is "+d.trackDistance(20,90)+" meters");
d.getOTP();
System.out.println("___________________________");
System.out.println("In view of the user");
System.out.println("The distance between user and driver is "+u.trackDistance(20,90)+" meters");
u.getOTP();
u.cabDetails();
u.rating();
}
}