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); }
private static void Print(Originator origin) { Console.WriteLine(origin.State.First); Console.WriteLine(origin.State.Second); }
public PrivateMemento(State state, Originator originator) { _originator = originator; _state = state; }