
Go语言命令模式请求封装1. 命令接口type Command interface { Execute() } type Receiver struct{} func (r *Receiver) Action() { fmt.Println(Receiver action) } type ConcreteCommand struct { receiver *Receiver } func (c *ConcreteCommand) Execute() { c.receiver.Action() } type Invoker struct { commands []Command } func (i *Invoker) ExecuteCommand(cmd Command) { cmd.Execute() }2. 总结命令模式将请求封装成对象允许参数化不同请求支持撤销操作。