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