definition: captures the internal state of an object without compromising encapsulation, and saves the state outside that object. This allows the object to be restored to its previously saved state
Class Diagram:
Structure:
- Initiator: records the internal state of the current moment and is responsible for defining which state is part of the backup scope and responsible for creating and recovering Memo data.
- Memo: responsible for storing the internal state of the initiator object, providing the internal state required by the initiator when needed.
- Administrative roles: manage memos, save and provide memos.
Advantages:
- When the status of the initiator role changes, it is possible that this is a wrong change, we can use the memo mode to restore the error.
- The status of the backup is saved outside the initiator role, so that the initiator role does not need to manage the status of each backup.
Disadvantages:
- In practical applications, the memo mode is multi-state and multi-backup, the status of the initiator role needs to be stored in the memo object, the consumption of resources is more serious.
Application Scenarios:
If there is a need to provide rollback operations, the use of Memo mode is ideal, such as JDBC transaction operations, text editor CTRL + Z recovery, and so on.
http://blog.csdn.net/zhengzhb/article/details/7697549
Memo Mode of design mode