⚪策略模式
Strategy Design Pattern
// 注意:并不能发挥策略模式的优势,此时策略模式实际上退化成了“面向对象的多态特性”或“基于接口而非实现编程原则”
EvictionStrategy evictionStrategy = new LruEvictionStrategy()
UserCache userCache = new UserCache(evictionStrategy)// 根据 type,用工厂创建
EvictionStrategy evictionStrategy = EvictionStrategyFactory.getEvictionStrategy(type)
UserCache userCache = new UserCache(evictionStrategy)OrderType type = order.getType()
DiscountStrategy discountStrategy = DiscountStrategyFactory.getDiscountStrategy(type)
discountStrategy.calDiscount(order)
设计原则
策略模式
Last updated