-
Notifications
You must be signed in to change notification settings - Fork 1
/
bridge.dart
60 lines (48 loc) · 1.31 KB
/
bridge.dart
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
// Message abstraction
abstract class Message {
final MessageSender sender;
Message(this.sender);
void send(String content);
}
// Concrete abstraction for SMS message
class SmsMessage extends Message {
SmsMessage(MessageSender sender) : super(sender);
@override
void send(String content) {
sender.sendMessage('SMS: $content');
}
}
// Concrete abstraction for Email message
class EmailMessage extends Message {
EmailMessage(MessageSender sender) : super(sender);
@override
void send(String content) {
sender.sendMessage('Email: $content');
}
}
// Interface for message sender
abstract interface class MessageSender {
void sendMessage(String content);
}
// Concrete sender through HTTP API
class HttpApiSender implements MessageSender {
@override
void sendMessage(String content) {
print('Sending via HTTP API: $content');
}
}
// Concrete sender through SMTP
class SmtpSender implements MessageSender {
@override
void sendMessage(String content) {
print('Sending via SMTP: $content');
}
}
void main() {
MessageSender httpApiSender = HttpApiSender();
MessageSender smtpSender = SmtpSender();
Message smsMessage = SmsMessage(httpApiSender);
smsMessage.send('Hello via HTTP API');
Message emailMessage = EmailMessage(smtpSender);
emailMessage.send('Hello via SMTP');
}