class Order { @Autowire OrderStatusActionRegister orderStatusActionRegister; void changeStatus(toStatus) { foreach(Action action : orderStatusActionRegister.getActions(toStatus)) { action.execute(); } } } interface Action { void execute(); } class OrderStatusActionRegister { Map<String, List> statusActionsMap = new HashMap<String, ArrayList>(); public void regitstr(status, action) { if(statusActionsMap.get(status) == null) { statusActionsMap.put(status, new ArrayList()); } statusActionsMap.get(status).add(action); } public void deregitstr() { ... } public List getActions(status) { return statusActionsMap.get(status); } } // 新增发货动作 class SendAction implement Action { void execute() { syso('业务逻辑-皓哥,我发货了,请嫂子查收'); } } class SendActionRegister { @Autowire OrderStatusActionRegister register; register.regitstr("发货", new SendAction()); }
虽然我不是高手,但我愿和你方便的交流。 QQ:370298543