package memento type Memento struct { state int } func NewMemento(value int) *Memento { return &Memento{state: value} } type Number struct { value int } func NewNumber(value int) *Number { return &Number{value: value} } func (n *Number) Double() { n.value *= 2 } func (n *Number) Hide() { n.value /= 2 } func (n *Number) Value() int { return n.value } func (n *Number) CreateMemento() *Memento { return NewMemento(n.value) } func (n *Number) ReginstateMemento(m *Memento) { n.value = m.state }