设计模式
设计模式
小熊123~
优秀是一种习惯
展开
-
设计模式在外卖营销业务中的实践
原文链接 策略模式 //定义一个策略接口 public interface Strategy { void strategyImplementation(); } //具体的策略实现(可以定义多个具体的策略实现) public class StrategyA implements Strategy{ @Override public void strategyImplementation() { System.out.println("正在执行策略A");转载 2021-01-19 15:09:39 · 55 阅读 · 0 评论 -
策略模式之枚举
//枚举(String -> Interface.method) public enum NotifyType { EMAIL("邮件", NotifyMechanismInterface.byEmail()), SMS("短信", NotifyMechanismInterface.bySms()), WECHAT("微信", NotifyMechanismInterface.byWeChat()); private String desc; privat.原创 2020-12-21 14:57:56 · 141 阅读 · 0 评论 -
单例模式手写
双重校验 public class Singleton { //私有构造 private Singleton(){ } //私有属性 private static Singleton instance; //双重校验 public Singleton getInstance(){ if(instance == null){ synchronized (Singleton.class){原创 2020-12-28 19:55:48 · 94 阅读 · 0 评论 -
策略模式实战
//返奖策略接口 public interface RewardStrategy { void reward(String userId); } //新用户返奖策略 public class NewUserRewardStrategy implements RewardStrategy { @Override public void reward(String userId) { System.out.println("new user [" + userId .原创 2021-01-19 16:04:46 · 182 阅读 · 0 评论 -
状态模式实战
//返奖状态 public abstract class RewardState { abstract void deal(String userId, String orderId); } //订单检查状态 public class OrderCheckState extends RewardState { @Override void deal(String userId, String orderId) { System.out.println("order.原创 2021-01-19 17:15:30 · 199 阅读 · 0 评论