command

package
v0.0.0-...-e059a18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 2 Imported by: 0

README

命令模式

命令模式也是一个响应模式,其主要作用是分离命令发出者和命令执行者,两者只要按照命令定义的约束交互,就可以各自变化。

现实生活中的例子也很多,比如,告知店员买XX奶茶,遥控器控制电视,就是命令模式,以及现在AI能力,大部分情况下,也是基于命令识别进行响应的,还有军训的时候,队列根据教官的各种口令进行变化,更多典型的命令模式。

命令模式中中的一个特点是每个命令都是一个类型(struct)。

命令模式的关键角色:

	*接收者(Receiver): 执行请求相关的操作Execute()
	*调用者(Invoker): 发出命令的一方
	*命令接口(Command)
	*具体命令的结构体(Command)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DrawCommand

type DrawCommand struct {
	Position *Position
}

DrawCommand 命令执行者 DrawCommand line to

func (*DrawCommand) Execute

func (d *DrawCommand) Execute() string

Execute cmd

type ICommand

type ICommand interface {
	Execute()
}

ICommand 命令接口,队列要进行响应

type Instructor

type Instructor struct {
	// contains filtered or unexported fields
}

Instructor 教官

func (*Instructor) AddCommand

func (i *Instructor) AddCommand(c ICommand)

AddCommand 教官喊口令一般都是一连串

func (*Instructor) Execute

func (i *Instructor) Execute()

Execute 教官的Execute是发出命令

type PathPainter

type PathPainter struct {
	// contains filtered or unexported fields
}

PathPainter invoke an draw command

func (*PathPainter) Append

func (p *PathPainter) Append(command command)

Append new cmd PathPainter

func (*PathPainter) Clear

func (p *PathPainter) Clear()

Clear all

func (*PathPainter) Execute

func (p *PathPainter) Execute() string

Execute run cmd

func (*PathPainter) Undo

func (p *PathPainter) Undo()

Undo last step cmd

type Position

type Position struct {
	X, Y int
}

Position pos

type Troop

type Troop struct {
	// contains filtered or unexported fields
}

Troop 队列

func (*Troop) Execute

func (t *Troop) Execute()

Execute cmd

type TurnBackCommand

type TurnBackCommand struct {
	// contains filtered or unexported fields
}

TurnBackCommand 向后转

func (*TurnBackCommand) Execute

func (t *TurnBackCommand) Execute()

Execute 执行向后转

type TurnLeftCommand

type TurnLeftCommand struct {
	// contains filtered or unexported fields
}

TurnLeftCommand 向左转

func (*TurnLeftCommand) Execute

func (t *TurnLeftCommand) Execute()

Execute 执行向左转

type TurnRightCommand

type TurnRightCommand struct {
	// contains filtered or unexported fields
}

TurnRightCommand 向右转

func (*TurnRightCommand) Execute

func (t *TurnRightCommand) Execute()

Execute 执行向右转

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL