| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package homework;
- /**
- * @author WanJl
- * @version 1.0
- * @title Notifiable
- * @description
- * @create 2026/7/24
- */
- public interface Notifiable {
- /**
- * 执行具体的发送逻辑
- * @param recipient
- * @param message
- */
- void doSend(String recipient, String message);
- /**
- * 校验参数
- * @param recipient
- * @param message
- * @return
- */
- default boolean validateParams(String recipient, String message){
- if (recipient!=null&&message!=null&&recipient!=""&&message!=""){
- System.out.println("参数校验通过");
- return true;
- }
- System.out.println("参数校验失败:收件人或消息不能为空");
- return false;
- }
- /**
- * 记录日志
- * @param level
- * @param msg
- */
- default void log(String level, String msg){
- System.out.println("["+level+"]消息:"+msg);
- }
- default void send(String recipient, String message){
- //1、校验参数
- boolean boo = validateParams(recipient, message);
- if (boo){
- //2、执行发送
- doSend(recipient,message);
- //3、记录日志
- log("INFO","发送成功");
- System.out.println("--- 发送流程结束 ---");
- }
- }
- /**
- * 输出
- */
- static void printNotificationType(){
- System.out.println("通知系统 v1.0——支持邮件/短信/微信通知");
- }
- }
|