Memento (Memo)-Object-Behavioral mode

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.