Pattern Application Background
In the computer room charge system, there is a window to change the basic data:
Since the data was changed in the text box. Just do not click Change button. is not updated to the database. So, the Cancel button here in the Personal edition reads the original data from the database and loads it into the window again. In this collaboration, the memo mode was added to deal with this cancel button again.
How to increase the mode
The basic idea is this:
1. Place the saved Basedata (the entity name of the base data Class) as a member variable inside the memo class. And pass in the basic data to be saved when the memo class is initialized.
2, define the data that the initiator uses to create and restore the memo, assuming that the click is canceled. This class is used to recover data in the data memo and return
3, using managers to manage the resulting memos
Class diagrams such as the following:
Advantages of Using Memo mode:
1, the access details of the basic data are encapsulated and stored in the Basedatamemento, which realizes the separation of the basic data storage and recovery;
2, avoid frequent access to the database to read the basic data
Defect Considerations for Memo mode
since the memo pattern is to encapsulate objects into a memo object, when it is assumed that the data to be saved is large, this time to memory, resources are often consumed more and better than reading the resource data to the database connection. Weigh the two implementations of the "Cancel" method, and this time we use this pattern to consider when necessary.
Cancel changes to basic data-app Memo mode