Notifiable.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package homework;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Notifiable
  6. * @description
  7. * @create 2026/7/24
  8. */
  9. public interface Notifiable {
  10. /**
  11. * 执行具体的发送逻辑
  12. * @param recipient
  13. * @param message
  14. */
  15. void doSend(String recipient, String message);
  16. /**
  17. * 校验参数
  18. * @param recipient
  19. * @param message
  20. * @return
  21. */
  22. default boolean validateParams(String recipient, String message){
  23. if (recipient!=null&&message!=null&&recipient!=""&&message!=""){
  24. System.out.println("参数校验通过");
  25. return true;
  26. }
  27. System.out.println("参数校验失败:收件人或消息不能为空");
  28. return false;
  29. }
  30. /**
  31. * 记录日志
  32. * @param level
  33. * @param msg
  34. */
  35. default void log(String level, String msg){
  36. System.out.println("["+level+"]消息:"+msg);
  37. }
  38. default void send(String recipient, String message){
  39. //1、校验参数
  40. boolean boo = validateParams(recipient, message);
  41. if (boo){
  42. //2、执行发送
  43. doSend(recipient,message);
  44. //3、记录日志
  45. log("INFO","发送成功");
  46. System.out.println("--- 发送流程结束 ---");
  47. }
  48. }
  49. /**
  50. * 输出
  51. */
  52. static void printNotificationType(){
  53. System.out.println("通知系统 v1.0——支持邮件/短信/微信通知");
  54. }
  55. }