Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

ts Command pattern

// The Command pattern is a design pattern lets you encapsulate all 
// information needed to perform an action in one object .
class Command {
  constructor(private receiver: Receiver) {}

  public execute() {
    this.receiver.action();
  }
}

const receiver = new Receiver();
const command = new Command(receiver);
const invoker = new Invoker();
invoker.setCommand(command);
invoker.execute();
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #ts #Command #pattern
ADD COMMENT
Topic
Name
3+6 =