Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Originator <StateObject> current = new Originator <StateObject>();

            current.SetState(new StateObject {
                Id = 0, Name = "Object 0"
            });
            CareTaker <StateObject> .SaveState(current);

            current.ShowState();

            current.SetState(new StateObject {
                Id = 1, Name = "Object 1"
            });
            CareTaker <StateObject> .SaveState(current);

            current.ShowState();

            current.SetState(new StateObject {
                Id = 2, Name = "Object 2"
            });
            CareTaker <StateObject> .SaveState(current);

            current.ShowState();

            current.SetState(new StateObject {
                Id = 3, Name = "Object 3"
            });
            CareTaker <StateObject> .SaveState(current);

            current.ShowState();

            CareTaker <StateObject> .RestoreState(current, 1);

            current.ShowState();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Originator o = new Originator();

            o.State = "On";

            // Store internal state

            Caretaker c = new Caretaker();

            c.Memento = o.CreateMemento();

            // Continue changing originator

            o.State = "Off";

            // Restore saved state

            o.SetMemento(c.Memento);

            // Wait for user

            Console.ReadKey();
        }
Exemplo n.º 3
0
 public static void RestoreState(Originator <T> orig, int checkpoint)
 {
     orig.RestoreMemento(mementoList[checkpoint]);
 }
Exemplo n.º 4
0
 public static void SaveState(Originator <T> orig)
 {
     mementoList.Add(orig.CreateMemento());
 }