예제 #1
0
        public static void Main(string[] args)
        {
            var origin = new Originator
            {
                State = new State
                {
                    First  = "123",
                    Second = "456"
                }
            };

            var caretaker = new Caretaker {
                Memento = origin.CreateMemento()
            };

            Print(origin);
            origin.State.First  = "qwe";
            origin.State.Second = "qwe";
            Print(origin);

            caretaker.Memento.RestoreState();
            Print(origin);
        }
예제 #2
0
 private static void Print(Originator origin)
 {
     Console.WriteLine(origin.State.First);
     Console.WriteLine(origin.State.Second);
 }
예제 #3
0
 public PrivateMemento(State state, Originator originator)
 {
     _originator = originator;
     _state      = state;
 }