Definition(Originated from the gof design pattern): capture the internal state of an object without damaging the closed state, and save the state outside the object. In this way, the object can be restored to the previously saved state.
Advantages and disadvantages of the memorandum Model
I. Advantages of the memorandum Model
1. Sometimes some internal information of the initiator object must be stored outside the initiator object, but it must be read by the initiator object itself,
The memorandum mode can be used to shield the internal information of the complex initiator from other objects, so as to properly maintain the encapsulated boundary.
2. This model simplifies initiation of humans. The initiators no longer need to manage and save versions of their internal states. The client can manage their own
The version of the desired status.
3. When the status of the initiator role changes, it may be invalid. In this case, you can use the currently stored memo to restore the status.
Ii. disadvantages of the memorandum model:
1. If the status of the initiator role needs to be completely stored in the memorandum object, the memorandum object will be expensive in terms of resource consumption.
2. When the owner's role stores a memorandum, the owner may not know how much storage space it will occupy, and thus cannot remind the user whether an operation is expensive.
3. When the status of the initiator role changes, the protocol may be invalid. If the success rate of the status change is not high, it is better to adopt the "if" protocol mode.
Taking the memo as an example, when I added a memo, I now changed the name of the memo and wanted to return to the previous memo data, the memorandum can be used to restore to the previous state.
This is just a simple test example. I hope that I can better understand the memorandum mode through these examples!
Form diagram:
No code is pasted here. Download the attachment by yourself!
: Http://files.cnblogs.com/xiaowei0705/MementoPattern.rar