C # simple memorandum mode (with source code download)

Source: Internet
Author: User

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

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.