<<< Pattern Four: Memento     Index    >>>

22. Implementing mementos

  • 
    class Memento {
    public:
        virtual ~Memento();
    
    private:
        friend class Item;
        Memento();
        //...
    };//class Memento
    
    class Item {
    public:
        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.

<<< Pattern Four: Memento     Index    >>>