Exemplo n.º 1
0
        static void Invock14()
        {
            Originator ori = new Originator();

            ori.State = "开";
            ori.Show();

            Caretaker car = new Caretaker();

            car.Memento = ori.CreateMemento();

            ori.State = "关";
            ori.Show();


            ori.SetMemento(car.Memento);
            ori.Show();
        }
Exemplo n.º 2
0
        // Memento
        public static void TetsMemento()
        {
            Console.WriteLine("- {0} -", typeof(Memento).Name);
            Console.WriteLine();

            Originator originator = new Originator();

            originator.State = "On";
            Console.WriteLine("Current state {0}", originator.State);
            Caretaker caretaker = new Caretaker();

            caretaker.Memento = originator.CreateMemento();
            originator.State  = "Off ";
            Console.WriteLine("Changed state {0}", originator.State);
            originator.SetMemento(caretaker.Memento);
            Console.WriteLine("First state {0}", originator.State);

            Console.WriteLine("***************************************");
            Console.WriteLine();
        }
Exemplo n.º 3
0
        static void Invock14()
        {
            Console.WriteLine("原始状态数据:");
            var ori = new Originator
            {
                State = "开"
            };

            ori.Show();

            Console.WriteLine("备忘状态:");
            var car = new Caretaker
            {
                Memento = ori.CreateMemento()
            };

            Console.WriteLine("改变原对象状态后:");
            ori.State = "关";
            ori.Show();

            Console.WriteLine("恢复对象状态后:");
            ori.SetMemento(car.Memento);
            ori.Show();
        }