Mode-engineering implementation and expansion memorandum mode Memento-self-test reference answer

Source: Internet
Author: User

1,

Interface IOriginator <T>
Where T: IState
{
/// <Summary>
/// Save a memo
/// </Summary>
/// <Remarks>
/// Default method -- full memo of all current data
/// </Remarks>
Void SaveCheckPoint ();

/// <Summary>
/// Restore a memo
/// </Summary>
/// <Remarks>
/// Default method -- restore the last full memo
/// </Remarks>
Void Undo ();

/// <Summary>
/// Save a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
Void SaveCheckPoint (string name );

/// <Summary>
/// Restore a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
Void Undo (string name );

/// <Summary>
/// Save a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
Void SaveCheckPoint (string name, string version );

/// <Summary>
/// Restore a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
Void Undo (string name, string version );

/// <Summary>
/// Save a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
/// <Param name = "subjectName"> business topic name </param>
Void SaveCheckPoint (string name, string version, string subjectName );

/// <Summary>
/// Restore a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
/// <Param name = "subjectName"> business topic name </param>
Void Undo (string name, string version, string subjectName );

/// <Summary>
/// Save a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
/// <Param name = "subjectName"> business topic name </param>
/// <Param name = "start"> start of the time interval </param>
/// <Param name = "end"> end of the time interval </param>
Void SaveCheckPoint (string name, string version, string subjectName, DateTime start, DateTime end );

/// <Summary>
/// Restore a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
/// <Param name = "subjectName"> business topic name </param>
/// <Param name = "start"> start of the time interval </param>
/// <Param name = "end"> end of the time interval </param>
Void Undo (string name, string version, string subjectName, DateTime start, DateTime end );
}
 

 

2. Integrate Memento and CoR

 

Example:

1) to simplify the example, replace the IState interface with string


2) CoR does not use the linked list method, but is implemented through the LINQ method.

3) each Handler in CoR is designed as an interface with closed operations (compression, signature, encryption, etc., and corresponding reverse processing is also required during recovery)


4) in the process of SaveCheckPoint () and Undo (), forward and reverse processes of CoR are called respectively.

 

Using System;
Using System. Collections. Generic;
Using System. Diagnostics;
Using System. Linq;
Using Microsoft. VisualStudio. TestTools. UnitTesting;
Namespace MarvellousWorks. PracticalPattern. Memento. Tests. Exercise
{
[TestClass]
Public class MementoCoRFixture
{
/// <Summary>
/// To simplify the definition of the primary interface, the type of the primary interface is directly defined.
/// </Summary>
Class Originator
{
Public string State {get; set ;}

Memento m;

Public HandlerCoRBuilder <string> HandlerCoRBuilder {get; set ;}

/// <Summary>
/// Define the memorandum as the internal type of the primary Device
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
Class Memento
{
Public string State {get; set ;}
}

/// <Summary>
/// Save the status to the memo
/// </Summary>
Public virtual void SaveCheckpoint ()
{
Trace. WriteLine ("Originator. void SaveCheckpoint ()-----------------");
M = new Memento ()
{
State = ProcessState (HandlerCoRBuilder. BuildUpProcessCoR (), this. State)
};
}
/// <Summary>
/// Restore the previous status from the Memorandum
/// </Summary>

Related Article

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.