美文网首页
备忘录模式

备忘录模式

作者: 小蜗牛Snail丶 | 来源:发表于2018-06-27 11:43 被阅读0次

OriGinator类:

.h: 

#include#include#include "Memento.h"

using namespace std;

#ifndef ORIGINATOR_H_

#define ORIGINATOR_H_

class OriGinator {

private :

string state;

public:

void setState(string value) {

state = value;

}

string getState() {

return state;

}

Memento * createMemento () {

return new Memento(state);

}

void setMemento (Memento *memento){

state = memento->state;

}

void show () {

cout << state <<endl;

}

Memento类

.h

#include#includeusing namespace std;

#ifndef MEMENTO_H_

#define MEMENTO_H_

class Memento {

private :

string state;

public:

Memento(string state){

this->state = state;

}

string State(){

return state;

}

};

Caretaker类

.h


#include#include#include "Memento.h"

using namespace std;

#ifndef CARETAKER_H_

#define CARETAKER_H_

class Caretaker {

private :

Memento memento;

public:

Memento * Memento () {

return memento;

}

void set (Memento * value )

{

memento = value;

}

};

相关文章

网友评论

      本文标题:备忘录模式

      本文链接:https://www.haomeiwen.com/subject/fidbyftx.html