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;
}
};