This design mode is to simply record the current status and then use the recorded data to recover.
For example, we first have a class that needs to record the current state for relevant work:
class Memo;class Human{public:string state;Memo *makeMemo();void restroDataFromMemo(Memo *m);void show(){cout<<"State: "<<state<<endl;}};
The state can be any defined data, depending on the actual situation.
Then we design a class that can keep state data according to this state:
class Memo{public:string state;Memo(string s) : state(s){}};
The following describes how to maintain and restore data:
Memo *Human::makeMemo(){return new Memo(state);}void Human::restroDataFromMemo(Memo *m){state = m->state;}
Then, let's look at the main function. We can use these two methods to maintain and recover data to convert the state and then restore it to the previous state:
int main(){Human human;human.state = "Get Ready";cout<<"\nThe current state:\n";human.show();Memo *m = human.makeMemo();cout<<"\nThe memo saved state:\n"<<m->state<<endl;cout<<"\nHuman set to new state:\n";human.state = "Handle distraction";human.show();cout<<"\nNow we use memo to restor previouse info.\n";human.restroDataFromMemo(m);human.show();delete m;return 0;}
In general, this is a very simple design model.
I think this design pattern can use general non-class methods to record the status, but when the data volume is very large, memo class can simplify the code, in addition, you can use classes to remember the data more easily, because the data is connected to a class.
If you want to make the design mode more complex, it is the State problem. For example, when the State is very complex, the design mode will naturally become complicated.