(JS)职责链模式
一步操作分为多个角色来完成
将角色分开,使用一个链串起来
class Action {
constructor(name) {
this.name = name;
this.nextAction = null;
}
setNextAction(action) {
this.nextAction = action;
}
handle() {
console.log(`${this.name}审批`);
if (this.nextAction != null) {
this.nextAction.handle();
}
}
}
let a1 = new Action("11");
let a2 = new Action("22");
let a3 = new Action("33");
a1.setNextAction(a2);
a2.setNextAction(a3);
a1.handle();
11审批
22审批
33审批