---
title: "备忘录模式Memento"
author: "nully"
date: "2016-02-02T10:19:52Z"
tags: []
categories: ["编程语言"]
slug: "memento"
draft: false
lastmod: "2016-02-02T10:23:32Z"
id: 2275396
url: "https://nully.iteye.com/blog/2275396"
---

备忘录模式Memento，也要快照模式。在不影响封装性的前提下，通过在外部将对象的内部状态进行捕获并存储起来，在适当的时候可以进行还原。

发起人提供备份和还原的方法，但是由外部对象维护备份的状态。

结构图：
![](http://dl2.iteye.com/upload/attachment/0114/9491/ef19822d-e17c-309f-a37f-3726b146e9f8.jpg)

![](http://dl2.iteye.com/upload/attachment/0114/9493/bb4cb3c1-055f-312a-a61c-5660b74beec0.jpg)

适用场景：
1.需要维护对象的内部状态，如UNDO、REDO操作