Exemple #1
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());
        }
Exemple #2
0
        public 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(String.Format("Current state: {0}", originator.getState()));

            originator.getStateFromMemento(caretaker.Get(0));
            Console.WriteLine(String.Format("First saved state: {0}", originator.getState()));
            originator.getStateFromMemento(caretaker.Get(1));
            Console.WriteLine(String.Format("Second saved state: {0}", originator.getState()));

            Console.ReadLine();
        }