public static void Main(String[] args) { Caretaker caretaker = new Caretaker(); Originator originator = new Originator(); originator.Set("State1"); originator.Set("State2"); caretaker.AddMemento(originator.SaveToMemento()); originator.Set("State3"); caretaker.AddMemento(originator.SaveToMemento()); originator.Set("State4"); originator.RestoreFromMemento(caretaker.GetMemento(1)); Console.ReadLine(); }
static void Main(string[] args) { List<Originator.Memento> savedStates = new List<Originator.Memento>(); Originator originator = new Originator(); originator.Set("State1"); originator.Set("State2"); savedStates.Add(originator.SaveToMemento()); originator.Set("State3"); // We can request multiple mementos, and choose which one to roll back to. savedStates.Add(originator.SaveToMemento()); originator.Set("State4"); originator.RestoreFromMemento(savedStates[1])); }
public void TestMemento() { var savedStates = new List <Originator.Memento>(); var originator = new Originator(); originator.Set("State1"); originator.Set("State2"); savedStates.Add(originator.SaveToMemento()); originator.Set("State3"); // We can request multiple mementos, and choose which one to roll back to. savedStates.Add(originator.SaveToMemento()); originator.Set("State4"); originator.RestoreFromMemento(savedStates[1]); }
public void TestMemento() { var careTaker = new CareTaker <string>(); var originator = new Originator <string>(); originator.State = "State 1"; careTaker.AddMemento(originator.SaveToMemento()); originator.State = "State 2"; careTaker.AddMemento(originator.SaveToMemento()); originator.State = "State 3"; originator.RestoreFromMemento(careTaker.GetMemento(1)); Assert.That(originator.State, Is.EqualTo("State 2")); }
public void SaveChange() { GameObject copy = Instantiate(gameState); SceneManager.MoveGameObjectToScene(copy, tmp); originator.SetState(gameState); careTaker.AddMemento(originator.SaveToMemento()); currentMemento++; totalMemento++; Debug.Log("Save Changed!"); Debug.Log("totalMemento!" + totalMemento); }
public void exitDetails(string city, bool delete) { if (delete) { og.setState(currentUser.Clone()); caretaker.AddMemento(og.SaveToMemento()); if (caretaker.Size() > 0) { button2.Show(); } else { button2.Hide(); } currentUser._cities.Remove(city); uservice.deletecity(city, currentUser); cities_window1.updateList(uservice.getcities(currentUser)); } cities_window1.Show(); detailedCity1.Hide(); }
static void Main(string[] args) { /** * ITERATOR **/ ConcreteAggregate collection = new ConcreteAggregate(); Iterator.Iterator iterator = collection.createIterator(); //use to iterator to go through the collection while (!iterator.isDone()) { Console.WriteLine(iterator.Next().ToString()); } /** * OBSERVER **/ Subject subject = new ConcreteSubject(SubjectState.Red); subject.Attach(new ConcreteObserver()); subject.Attach(new ConcreteObserver()); subject.Attach(new ConcreteObserver()); ((ConcreteSubject)subject).SubjectState = SubjectState.Blue; /** * DECORATOR **/ //we create a class with a base function Component component = new ConcreteComponent(); //we create the function we want the add to the first class Decorator.Decorator decorator = new ConcreteDecorator(); //the decorator gets the functionality of the class we want to extend decorator.SetBaseFuntionality(component); //both ops are called decorator.Operation(); /** * COMMAND **/ Command.Command command = new ConcreteCommand(new Receiver()); //create an invoker which in turn calls the command which IN TURN calls the receiver Invoker invoker = new Invoker(); invoker.SetCommand(command); invoker.ExecuteCommand(); /** * COMPOSITE **/ //instanciate differents persons Composite.Component component1 = new Composite.Composite("Bob"); Composite.Component component2 = new Composite.Composite("Patrick"); Composite.Component component3 = new Composite.Composite("Johny"); Composite.Component component4 = new Composite.Composite("Pierre"); //affects differents persons to a superior component1.Add(component2); component2.Add(component3); component2.Add(component4); //default method for every objects in the tree component1.Operation(); /** * MEMENTO **/ Originator originator = new Originator(); CareTaker careTaker = new CareTaker(); //create a couple of states originator.State = "state1"; originator.State = "state2"; //save at some point careTaker.Add(originator.SaveToMemento()); originator.State = "state3"; //restore state at the time of the save originator.RestoreStateFromMemento(careTaker.Get(0)); Console.WriteLine(originator.State); Console.ReadKey(); }
public void SetState(SavedState _savedState)// string[] _imgList, TaskState _stateTask) { m_originator.SetState(_savedState); m_carTaker.Add(m_originator.SaveToMemento()); }