Esempio n. 1
0
        // Client
        static void Main()
        {
            // References to the mementos
            Caretaker[] c          = new Caretaker[10];
            Originator  originator = new Originator();
            int         move       = 0;
            // Iterator for the moves
            Simulator simulator = new Simulator();

            foreach (string command in simulator)
            {
                // Check for undo
                if (command[0] == '*' && move > 0)
                {
                    originator.GetMemento(c[move - 1].Memento);
                }
                else
                {
                    originator.Operation(command);
                }
                move++;
                c[move]         = new Caretaker();
                c[move].Memento = originator.SetMemento();
            }
        }
Esempio n. 2
0
            public static void Run()
            {
                Originator org = new Originator();

                Console.WriteLine(org);
                var m = org.GetMemento();

                Console.WriteLine($"Momento Captured at {m.TimeStamp}");
                org.StateChangingOperation();
                Console.WriteLine(org);
                org.RevertToState(m);
                Console.WriteLine(org);
                Console.ReadKey();
            }