public static void Output()
        {
            var originator = new Originator();
            var careTaker  = new CareTaker();

            originator.State = "State #1";
            originator.State = "State #2";
            careTaker.Add(originator.SaveStateToMemento());

            originator.State = "State #3";
            careTaker.Add(originator.SaveStateToMemento());

            originator.State = "State #4";
            Trace.WriteLine("Current State: " + originator.State + Environment.NewLine);

            originator.GetStateFromMemento(careTaker.Get(0));
            Trace.WriteLine("First saved State: " + originator.State + Environment.NewLine);
            originator.GetStateFromMemento(careTaker.Get(1));
            Trace.WriteLine("Second saved State: " + originator.State + Environment.NewLine);
        }
Пример #2
0
        public void SaveToMemento()
        {
            Originator originator = new Originator(this._originator.GetState());

            this._mementolist.Add(new Memento(originator));
        }
Пример #3
0
 public void SetState(Originator state)
 {
     this._personinfo = state._personinfo;
 }
Пример #4
0
 public CareTaker(Originator originator)
 {
     this._originator = originator;
 }