备忘录模式

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;

}

};




©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容