1. Intentions
captures the internal state of an object and stores it outside the object, if the cloth destroys encapsulation. This allows the object to be restored to its previously saved state.
2. Aliases
Token
3. Motivation
To allow the user to cancel an indeterminate operation or recover from an error, you need to implement checkpoints and cancellation mechanisms, and to implement these mechanisms, you must save the state information somewhere so that the objects can be restored to their previous state. A memo is an object that stores the internal state of another object in an instant, which is referred to as the original sender of the memo.
4. Applicability
- You must save the state of an object at a certain point in time so that it can revert back to its previous state if needed later.
- If one uses interfaces to get these states directly from other objects, it exposes the implementation details of the object and destroys the encapsulation of the object.
5. Structure
6. Effects
- Keeping the boundary encapsulated uses a memo to avoid exposing information that should only be managed by the original and that must be stored outside of the original sender.
- simplifies the original generator in other packaging-preserving designs, originator is responsible for maintaining the internal state version requested by the customer.
- The use of memos can be costly if the source must copy and store a large amount of information when generating a memo, or if the customer creates a memo and restores the status of the generator very frequently, it can cause a very high overhead.
- Defines a narrow interface and a wide interface.
- The potential cost of maintaining a memo.
Memento (Memo)-Object-Behavioral mode