-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge.js
More file actions
67 lines (55 loc) · 2.07 KB
/
bridge.js
File metadata and controls
67 lines (55 loc) · 2.07 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
class NotificationSender {
send(message) {
throw new Error('Method `send()` should be overridden')
}
}
class TelegramSender extends NotificationSender {
send(message) {
console.log(`Sending notification in Telegram: "${message}"`)
}
}
class WhatsAppSender extends NotificationSender {
send(message) {
console.log(`Sending notification in WhatsApp: "${message}"`)
}
}
class Notification {
constructor(sender) {
this.sender = sender
}
sendNotification(message) {
throw new Error('Method `sendNotification()` should be overridden')
}
}
class InstantNotification extends Notification {
sendNotification(message) {
console.log('Instant notification has been sent')
this.sender.send(message)
}
}
class DelayedNotification extends Notification {
sendNotification(message) {
console.log('Delayed notification will be sent in 5 seconds...')
setTimeout(() => {
this.sender.send(message)
}, 5000)
}
}
const telegramSender = new TelegramSender()
const whatsAppSender = new WhatsAppSender()
const instantTelegramNotification = new InstantNotification(telegramSender)
instantTelegramNotification.sendNotification('Hello from Telegram!')
const instantWhatsAppNotification = new InstantNotification(whatsAppSender)
instantWhatsAppNotification.sendNotification('Hello from WhatsApp!')
const delayedTelegramNotification = new DelayedNotification(telegramSender)
delayedTelegramNotification.sendNotification('Delayed notification from Telegram')
const delayedWhatsAppNotification = new DelayedNotification(whatsAppSender)
delayedWhatsAppNotification.sendNotification('Delayed notification from WhatsApp')
// Instant notification has been sent
// Sending notification in Telegram: "Hello from Telegram!"
// Instant notification has been sent
// Sending notification in WhatsApp: "Hello from WhatsApp!"
// Delayed notification will be sent in 5 seconds...
// Delayed notification will be sent in 5 seconds...
// Sending notification in Telegram: "Delayed notification from Telegram"
// Sending notification in WhatsApp: "Delayed notification from WhatsApp"