static void Main(string[] args) { Book book = new Book { Isbn = "12345", Title = "Sefiller", Author = "Victor Hugo" }; book.ShowBook(); CareTaker history = new CareTaker(); history.Memento = book.CreateUndo(); book.Isbn = "54321"; book.Title = "SEFİLLER"; book.ShowBook(); book.RestoreFromUndo(history.Memento); book.ShowBook(); }
static void Main(string[] args) { Originator <StateObject> current = new Originator <StateObject>(); current.SetState(new StateObject { Id = 0, Name = "Object 0" }); CareTaker <StateObject> .SaveState(current); current.ShowState(); current.SetState(new StateObject { Id = 1, Name = "Object 1" }); CareTaker <StateObject> .SaveState(current); current.ShowState(); current.SetState(new StateObject { Id = 2, Name = "Object 2" }); CareTaker <StateObject> .SaveState(current); current.ShowState(); current.SetState(new StateObject { Id = 3, Name = "Object 3" }); CareTaker <StateObject> .SaveState(current); current.ShowState(); CareTaker <StateObject> .RestoreState(current, 1); current.ShowState(); Console.ReadKey(); }