update:demo13

This commit is contained in:
dichgrem
2026-01-21 14:35:47 +08:00
parent a7334f14dc
commit 441cb7d898
6 changed files with 392 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
package com.study.demo13;
interface Notifier {
void send(String message, int level);
String getChannel();
}
class EmailNotifier implements Notifier {
private String channel = "EMAIL";
@Override
public void send(String message, int level) {
System.out.println("[EMAIL] " + (level >= 3 ? "[紧急] " : "") + message);
}
@Override
public String getChannel() {
return channel;
}
}
class SMSNotifier implements Notifier {
private String channel = "SMS";
@Override
public void send(String message, int level) {
System.out.println("[SMS] " + (level >= 3 ? "[紧急] " : "") + message);
}
@Override
public String getChannel() {
return channel;
}
}
class PushNotifier implements Notifier {
private String channel = "PUSH";
@Override
public void send(String message, int level) {
System.out.println("[PUSH] " + (level >= 3 ? "[紧急] " : "") + message);
}
@Override
public String getChannel() {
return channel;
}
}
public class NotificationService {
public static void main(String[] args) {
Notifier email = new EmailNotifier();
Notifier sms = new SMSNotifier();
Notifier push = new PushNotifier();
email.send("您的订单已发货", 1);
sms.send("验证码: 123456", 2);
push.send("账户安全警告", 3);
email.send("重要通知:系统维护", 4);
System.out.println("\n通知渠道类型");
System.out.println("Email渠道: " + email.getChannel());
System.out.println("SMS渠道: " + sms.getChannel());
System.out.println("Push渠道: " + push.getChannel());
}
}