Design Pattern _ memento _ memorandum Pattern

Source: Internet
Author: User

Image example:

When chatting with a few mm users, you must remember what you said to mm just now. Otherwise, MM will be unhappy. Fortunately, I have a memorandum, I copied a copy of what I said to the mm and saved it in the memo so that I can view the previous records at any time.

Memorandum mode:

A memorandum object is an object used to store snapshots of another object's internal state. The purpose of the memorandum mode is to catch the state of an object without damaging the encapsulation, and store it externally, in this way, this object can be restored to the stored state when appropriate in the future.

 

Purpose:
Capture the internal state of an object without interrupting encapsulation, and save the state outside the object. In this way, the object can be restored to the original state.

UML structure diagram:


Resolution:
In memento mode, the state to be saved is encapsulated. It is retrieved and restored only when it needs to be restored. the principle is very simple. Pay attention to the narrow interface and wide interface. the so-called wide interface is an interface in the general sense. It uses an external interface as a public member. The narrow interface, on the contrary, uses the interface as a private member, the class that needs to access these interface functions is used as the friend class of this class, that is, the interface is only exposed to the class that is interested in these interfaces, rather than exposed to the outside. the following implementation is implemented using a narrow implementation method.

 

Design Pattern _ memento _ memorandum Pattern

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.