Esempio n. 1
0
        static void Main(string[] args)
        {
            //var memento = someWriter.CreateMemento();
            //someWriter.startWriting();

            FoodSupplier s = new FoodSupplier();

            s.Name  = "Harold Karstark";
            s.Phone = "(482) 555-1172";
            // Let's store that entry in our database.
            SupplierMemory m = new SupplierMemory();

            m.Memento = s.SaveMemento();
            // Continue changing originator
            s.Address = "548 S Main St. Nowhere, KS";
            // Crap, gotta undo that entry, I entered the wrong address
            s.RestoreMemento(m.Memento);
            Console.ReadKey();
        }
Esempio n. 2
0
        /// <summary>
        /// In the Memento pattern, we need to capture and externalize an object's state so that the object can be
        /// restored to that state at a later time.  A good example of this is undo/redo operations.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Here's a new supplier for our restaurant
            FoodSupplier foodSupplier = new FoodSupplier();

            foodSupplier.Name  = "David Noho";
            foodSupplier.Phone = "050679485";

            // Let's store that entry in our database.
            SupplierMemory supplierMemory = new SupplierMemory();

            // using the caretaker to save our memento data
            supplierMemory.Memento = foodSupplier.SaveMemento();

            // Continue changing originator
            foodSupplier.Address = "Tel Aviv";

            // Crap, gotta undo that entry, I entered the wrong address
            // using the caretaker to retrieve our memento saved data
            foodSupplier.RestoreMemento(supplierMemory.Memento);

            Console.ReadKey();
        }