📰 来源: 博客园 本文是【GoF设计模式】系列第14篇,更多内容欢迎关注公众号:咖啡八杯 电商网站结算时常常要算优惠:新用户满减、不同等级会员打折、节日活动满减。最直觉的写法是把所有规则塞进一个方法里用 if-else 区分: class Cashier { public int calc(int total, String type) { if ("打九折".equals(type)) { return (int) (total * 0.9); } else if ("满300减40".equals(type)…