<<< Memento Structure     Index     Observer >>>

59. Memento Implementation

    class Memento {
        virtual ~Memento();
        friend class Item;
    };//class Memento
    class Item {
        Memento* create_memento();
        void restore_memento( Memento* );
    };//class Item
  • Class Item is the originator with some internal states.

  • The user of Item::create_memento( ) and Item::restore_memento( ) is commonly referred to as a caretaker.

  • We usually want Memento objects be created only by Item::create_memento( ).

  • We might also want to allow incremental restoration via a stack of Mementos.

  • It is possible to implement Memento file I/O (or database) interface to add persistence of states.

<<< Memento Structure     Index     Observer >>>