-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObservableDP.java
More file actions
154 lines (107 loc) · 3.22 KB
/
ObservableDP.java
File metadata and controls
154 lines (107 loc) · 3.22 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import java.util.*;
interface NotifyInterface {
public void sendMsg();
}
class EmailMsgListener implements NotifyInterface {
public final String email;
public EmailMsgListener(String email) {
this.email = email;
}
public void sendMsg() {
System.out.println("Email sent to " + email);
}
}
class AppNotificationListener implements NotifyInterface {
public final String userName;
public AppNotificationListener(String un) {
this.userName = un;
}
public void sendMsg() {
System.out.println("Notification has been sent to " + userName);
}
}
class NotificationService {
private final List<NotifyInterface> customerList;
public NotificationService() {
customerList = new ArrayList<>();
}
public void subscribe(NotifyInterface listener) {
customerList.add(listener);
}
public void unsubscribe(NotifyInterface listener) {
customerList.remove(listener);
}
public void noticeAll() {
customerList.forEach(listener -> listener.sendMsg());
}
}
class Store {
public NotificationService notificationService;
public Store() {
this.notificationService = new NotificationService();
}
public void newItemPromotion() {
notificationService.noticeAll();
}
}
class obsdp {
public void main(String[] args) {
Store store = new Store();
store.notificationService.subscribe(
new EmailMsgListener("kaushal21gs@gmail.com")
);
store.notificationService.subscribe(
new EmailMsgListener("thondakumar27@gmail.com")
);
store.notificationService.subscribe(
new AppNotificationListener("kaushals_dev")
);
store.notificationService.noticeAll();
}
}
// import java.util.*;
// interface NotifyInterface {
// public void notice();
// }
// class EmailMsgListener implements NotifyInterface {
// public final String email;
// public EmailMsgListener(String email) {
// this.email = email;
// }
// public void notice() {
// System.out.println("The email has been successfully went to " + email);
// }
// }
// class NotificationService {
// public List<NotifyInterface> customers;
// public NotificationService() {
// customers = new ArrayList<>();
// }
// public void subscribe(NotifyInterface listener) {
// customers.add(listener);
// }
// public void unsubscribe(NotifyInterface listener) {
// customers.remove(listener);
// }
// public void noticeAll() {
// customers.forEach(listener -> listener.notice());
// }
// }
// class Store {
// public NotificationService notificationService;
// public Store() {
// notificationService = new NotificationService();
// }
// }
// class obsdp {
// public void main(String[] args) {
// Store store = new Store();
// store.notificationService.subscribe(
// new EmailMsgListener("kaushal21gs@gmail.com")
// );
// store.notificationService.subscribe(
// new EmailMsgListener("triansh24gs@gmail.com")
// );
// store.notificationService.noticeAll();
// }
// }