Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Originator orig      = new Originator();
            CareTaker  careTaker = new CareTaker();

            orig.setState("State1");
            orig.setState("State2");
            careTaker.add(orig.saveStateToMemento());

            orig.setState("State3");
            careTaker.add(orig.saveStateToMemento());

            careTaker.get(0);
            orig.restoreFromMemento(careTaker.get(1));

            Console.Read();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Originator origin = new Originator();
            CareTaker  taker  = new CareTaker();

            origin.setState("State #1");
            origin.setState("State #2");
            taker.add(origin.saveStateToMemento());
            origin.setState("State #3");
            taker.add(origin.saveStateToMemento());
            origin.setState("State #4");

            // current state
            Console.WriteLine("Current state: " + origin.getState());
            origin.getStateFromMemento(taker.get(0));
            Console.WriteLine("First saved state: " + origin.getState());
            origin.getStateFromMemento(taker.get(1));
            Console.WriteLine("Second saved state: " + origin.getState());

            Console.Read();
        }