example

package
v0.0.0-...-05962f3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcreteStateA

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

ConcreteStateA 描述了打开按钮的状态

func (*ConcreteStateA) Off

func (cs *ConcreteStateA) Off(m *Context)

将状态从打开切换到关闭

func (*ConcreteStateA) On

func (cs *ConcreteStateA) On(m *Context)

具体状态A的打开方法

type ConcreteStateB

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

ConcreteStateB 描述关闭按钮状态

func (*ConcreteStateB) Off

func (cs *ConcreteStateB) Off(m *Context)

具体状态B的关闭方法

func (*ConcreteStateB) On

func (cs *ConcreteStateB) On(m *Context)

将状态从关闭切换到打开

type Context

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

上下文定义了可以打开和关闭的状态

func NewContext

func NewContext() *Context

初始化上下文

func (*Context) ChangeState

func (c *Context) ChangeState(s State)

ChangeState 设置上下文的当前状态

func (*Context) Off

func (c *Context) Off()

按下关闭按钮

func (*Context) On

func (c *Context) On()

按下打开按钮

type State

type State interface {
	On(m *Context)
	Off(m *Context)
}

描述了上下文的内部状态

func NewConcreteStateA

func NewConcreteStateA() State

创建一个新的具体状态A

func NewConcreteStateB

func NewConcreteStateB() State

NewConcreteStateB 创建一个新的具体状态B

Jump to

Keyboard shortcuts

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