public static void Demo() { Originator o = new Originator() { State = "1" }; CareTaker ct = new CareTaker(); o.State = "2"; ct.Add(o.Memento); o.State = "3"; ct.Add(o.Memento); o.State = "4"; Console.WriteLine("Current State " + o.State); o.Memento = ct.Get(0); Console.WriteLine("First State " + o.State); o.Memento = ct.Get(1); Console.WriteLine("Second State " + o.State); Console.Read(); }
static void Main(string[] args) { Originator originator = new Originator(); CareTaker careTaker = new CareTaker(); originator.State = "State1"; originator.State = "State2"; originator.State = "State3"; careTaker.Add(originator.SaveStateToMemento()); originator.State = "State4"; careTaker.Add(originator.SaveStateToMemento()); Console.WriteLine(originator.GetStateFromMemento(careTaker.Get(0))); Console.WriteLine(originator.GetStateFromMemento(careTaker.Get(1))); Console.ReadLine(); }
static void Main(string[] args) { Originator originator = new Originator(); CareTaker 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"; Console.WriteLine("Current State: " + originator.State); originator.GetStateFromMemento(careTaker.Get(0)); Console.WriteLine("First saved State: " + originator.State); originator.GetStateFromMemento(careTaker.Get(1)); Console.WriteLine("Second saved State: " + originator.State); Console.ReadKey(); }
static void Main() { 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()); }