Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

命令模式 #460

Open
LittlebearHat opened this issue Feb 11, 2023 · 0 comments
Open

命令模式 #460

LittlebearHat opened this issue Feb 11, 2023 · 0 comments

Comments

@LittlebearHat
Copy link
Contributor

class Receiver {
  //我是接收者
  execute() {
    console.log("接收者执行请求");
  }
}
class Command {
  //我是命令对象
  constructor(receiver) {
    this.receiver = receiver;
  }
  execute() {
    // 调用接收者对应接口执行
    console.log("命令对象处理发布者请求");
    this.receiver.execute();
  }
}
class Invoker {
  //我是发布者
  constructor(command) {
    this.command = command;
  }
  invoke() {
    // 调用命令
    console.log("发布者发布请求");
    this.command.execute();
  }
}
const receiver = new Receiver();
const command = new Command(receiver);
const invoker = new Invoker(command);
invoker.invoke();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant