[Project actual combat] Memento mode of design mode (Memento)

1. What is the memo mode?

The Memento pattern is a behavioral design pattern that allows you to capture the internal state of an object and save that state outside the object without breaking encapsulation. This allows the object to be restored to its previously saved state later.

Memento: This is a snapshot that stores the internal state of the sponsor object, usually a data structure containing the sponsor state.

2. Basic functions of memo mode

The basic functions provided by the memento mode are: saving object state information (snapshot), undo, redo and history.

3. Two interfaces of memo mode

Memento mode generally provides two interfaces: wide interface and narrow interface.
The entire object state can be obtained through the wide interface, which will expose the internal information of the memo object.
Through the narrow interface, only limited information can be accessed, which can effectively prevent information leakage.

Fourth, the advantages of the memorandum model

(1) Provide the user with a mechanism to restore the state, enabling the user to return to a certain historical state more conveniently.
(2) Encapsulation of information is achieved, so that users do not need to care about the details of state preservation.

5. Disadvantages of memo mode

Consumption of resources, if there are too many member variables of the class, it will inevitably occupy relatively large resources, and each save will consume a certain amount of memory.

Guess you like

Origin blog.csdn.net/wstever/article/details/129655709