Ejemplo n.º 1
0
        // we can ask a point to write its current state
        // into new memento object and return it to us
        public CMemento createMemento()
        {
            // create a new memento
            CMemento memento = new CMemento();

            // store actual data inside it
            memento.setState(_x, _y);
            // and return it
            return(memento);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // create a CPoint
            CPoint p = new CPoint(10, 20);

            // ask a CPoint to report its current state
            p.report();

            // ask a CPoint to create its current memento
            CMemento memento = p.createMemento();

            // now we can change a point to another destination
            p.move(5, 5);
            // ask a CPoint to report its current state
            p.report();

            // however, having a memento object, we can always ask CPoint
            // to return back to the state it was when memento was created
            p.updateFromMemento(memento);
            // ask a CPoint to report its current state
            p.report();

            Console.ReadKey();
        }
Ejemplo n.º 3
0
 // we can give the object a memento it has created
 // a long time ago, and to ask it to read its state from memento
 public virtual void updateFromMemento(CMemento memento)
 {
     // read actual data from memento
     memento.getState(ref _x, ref _y);
 }