//Caretaker
        static void Main(string[] args)
        {
            IList <Memento> undos   = new List <Memento>();
            Notepad         notepad = new Notepad();
            Memento         undo;

            //First Revision
            undo = notepad.SetText("cool");
            undos.Add(undo);

            Console.WriteLine("Currently in the notepad:");
            Console.WriteLine(notepad.GetText());

            //Second Revision
            undo = notepad.SetText("Something cool, but not cool enough to impress you!");
            undos.Add(undo);

            Console.WriteLine("\nCurrently in the notepad:");
            Console.WriteLine(notepad.GetText());

            Console.WriteLine("\nIssue Undo command");
            notepad.Undo(undos[1]);

            Console.WriteLine("\nCurrently in the notepad <after undo>:");
            Console.WriteLine(notepad.GetText());

            Console.Read();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            IList <Memento> undos = new List <Memento>();

            Notepad notepad = new Notepad();


            Memento undo;


            // frist revision

            undo = notepad.SetText("cool");

            undos.Add(undo);

            Console.WriteLine("curretly in the notepade   ");
            Console.WriteLine(notepad.GetText());



            // sec revision

            undo = notepad.SetText("hello,  i ma m, if youare reidng  cool ");

            undos.Add(undo);


            Console.WriteLine("currenlty in the notepad ++  ");

            Console.WriteLine(notepad.GetText());

            Console.WriteLine("issue undo cmd   ");

            notepad.Undo(undos[1]);



            Console.WriteLine("curretly in the notepade (after undo   ");
            Console.WriteLine(notepad.GetText());


            Console.WriteLine("issue undo cmd   ");

            notepad.Undo(undos[0]);

            Console.WriteLine("curretly in the notepade (after undo   ");
            Console.WriteLine(notepad.GetText());


            Console.ReadKey();
        }