Memento

A caretaker needs to save a former state of an originator in case that state needs to be restored at a later time, but we don't want the caretaker to know too much about the private internal state of the originator.

Implementation

In C++ we can make the memento a friend of the originator.

In Java we can make memento an interface implemented by an inner class of the originator.