예제 #1
0
        static void Main(string[] args)
        {
            Originator <int> originator = new Originator <int>();

            originator.State = 1;
            CareTaker <int> careTaker = new CareTaker <int>();

            careTaker.Memento = originator.Redo();

            Console.WriteLine(originator.State.ToString());

            originator.State = 2;
            Console.WriteLine(originator.State.ToString());

            originator.Undo(careTaker.Memento);

            Console.WriteLine(originator.State.ToString());
        }
예제 #2
0
        static void Main(string[] args)
        {
            Originator originator = new Originator();
            CareTaker  careTaker  = new CareTaker();

            originator.SetState("State #1");
            originator.SetState("State #2");
            careTaker.Add(originator.SaveStateToMemento());
            originator.SetState("State #3");
            careTaker.Add(originator.SaveStateToMemento());
            originator.SetState("State #4");

            Console.WriteLine($"Current State:{originator.GetState()}");
            originator.GetStateFromMemento(careTaker.Get(0));
            Console.WriteLine($"First saved State:{originator.GetState()}");
            originator.GetStateFromMemento(careTaker.Get(1));
            Console.WriteLine($"Second saved State:{originator.GetState()}");

            Console.ReadKey();
        }