memento

package
v0.0.0-...-eb36113 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0, MIT Imports: 1 Imported by: 0

README

备忘录模式

备忘录模式用于保存程序内部状态到外部,又不希望暴露内部状态的情形。

程序内部状态使用窄接口传递给外部进行存储,从而不暴露程序实现细节。

备忘录模式同时可以离线保存内部状态,如保存到数据库,文件等。

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

type Game struct {
	// contains filtered or unexported fields
}
Example
game := &Game{
	hp: 10,
	mp: 10,
}

game.Status()
progress := game.Save()

game.Play(-2, -3)
game.Status()

game.Load(progress)
game.Status()
Output:

Current HP:10, MP:10
Current HP:7, MP:8
Current HP:10, MP:10

func (*Game) Load

func (g *Game) Load(m Memento)

func (*Game) Play

func (g *Game) Play(mpDelta, hpDelta int)

func (*Game) Save

func (g *Game) Save() Memento

func (*Game) Status

func (g *Game) Status()

type Memento

type Memento interface{}

Jump to

Keyboard shortcuts

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