1. Memorandum Mode

Source: Internet
Author: User

1. Memorandum Mode
The core content of the memorandum of understanding 1 is:

A: Structure of the stored records (stored using classes)

B: Record generation class

C: Use a Data Structure to store operation records

2. The function of the memorandum mode is to play back the operations performed.

3. Description of the memorandum Mode

Memorandum mode: A memorandum object is an object used to store snapshots of the internal state of another object.

The purpose of the memorandum mode is to catch the state of an object without damaging the encapsulation,

In addition, the object is stored externally, so that the object can be restored to the stored state when appropriate in the future.

When chatting with several MM users, you must remember what you said to MM just now.

Otherwise, MM will be unhappy when it finds out. Fortunately, I have a memorandum,

I copied a copy of what mm I said and saved it in the memo,

In this way, you can view previous records at any time.

Design the software for playback and record the state of the event. Database Backup, Document compilation, cancellation, and recovery

Three steps

A Design Record node, storage record, // record mouse, keyboard status

B design record storage, vector, list, map, set, linked list, graph, array, tree

C operation record class, record the node status, set the node status, display the status, 0.1 seconds to record

4. Memorandum mode class diagram

5. Code:

# Include

# Include

# Include

Usingnamespacestd;

// Memorandum mode: A memorandum object is an object used to store snapshots of the internal state of another object.

// The purpose of the memorandum mode is to catch the state of an object without damaging the encapsulation,

// It is stored externally, so that this object can be restored to the stored State at an appropriate time in the future.

// When chatting with several MM at the same time, you must remember what you said to MM just now.

//, Or MM will be unhappy if it finds out. Fortunately, I have a memorandum,

// I copied a copy of what I said to the MM and saved it in the memo,

// You can view previous records at any time.

// Design the software for playback and record the state of the event. Database Backup, Document compilation, cancellation, and recovery

// Three steps of the design Memorandum

// 1. Design Record node, storage record, // record mouse, keyboard status

// 2. Design record storage, vector, list, map, set, linked list, graph, array, and tree

// 3. Operation record class, record node status, set node status, display status, 0.1 seconds record

// The node of the Memorandum. Below are the recorded nodes that store the record information.

// Class as the storage structure

ClassMemo

{

Public:

Stringstate;

Memo (stringstate) // record the current state

{

This-> state = state;

}

};

// The node of the class that contains the Memorandum. Originator indicates the initiator, origin, and origin.

// Act as the operation class

ClassOriginator

{

Public:

Stringstate;

VoidsetMemo (Memo * memo)

{

State = memo-> state;

}

Memo * createMemo ()

{

ReturnnewMemo (state );

}

Voidshow ()

{

Cout <

}

};

// A collection of memos as a storage structure

ClassCaretaker

{

Public:

Vector Memo;

Voidsave (Memo * memo)

{

(This-> memo). push_back (memo );

}

Memo * getState (inti)

{

Returnmemo [I];

}

};

Intmain ()

{

// Operation class

Originator * og = newOriginator ();

// Storage Structure

Caretaker * ct = newCaretaker ();

Og-> state = "on ";

Og-> show ();

Ct-> save (og-> createMemo ());

Og-> state = "off ";

Og-> show ();

Ct-> save (og-> createMemo ());

Og-> state = "middle ";

Og-> show ();

Ct-> save (og-> createMemo ());

Og-> setMemo (ct-> getState (1 ));

Og-> show ();

Og-> setMemo (ct-> getState (2 ));

Og-> show ();

Cin. get ();

Return 0;

}

Running result:

Zookeeper

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.