Beispiel #1
0
        static void Main(string[] args)
        {
            SalesProspect s = new SalesProspect();

            s.Name   = "Noel van Halen";
            s.Phone  = "(412) 256-0990";
            s.Budget = 25000.0;

            ProspectMemory m = new ProspectMemory();

            m.Memento = s.SaveMemento();


            s.Name   = "Leo Welch";
            s.Phone  = "(310) 209-7111";
            s.Budget = 1000000.0;

            s.RestoreMemento(m.Memento);
            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            SalesProspect prospect = new SalesProspect("Atanas", "088 8999 891", 200);

            Console.WriteLine("Initial state");
            Console.WriteLine(prospect);

            Console.WriteLine("Saving state\n");
            ProspectMemory prospectMemory = new ProspectMemory();

            prospectMemory.Memento = prospect.SaveMemento();

            Console.WriteLine("Change initial prospect");
            prospect.Name   = "Nasko";
            prospect.Phone  = "123 456 789";
            prospect.Budget = 132456;
            Console.WriteLine(prospect);

            Console.WriteLine("Restore intitial state");
            prospect.RestoreMemento(prospectMemory.Memento);
            Console.WriteLine(prospect);
        }
        public void Test()
        {
            SalesProspect s = new SalesProspect();

            s.Name   = "xiaoming";
            s.Phone  = "(010)65236523";
            s.Budget = 28000.0;

            //Store internal state
            ProspectMemory m = new ProspectMemory();

            m.Memento = s.SaveMemento();

            //Continue changing originator
            s.Name   = "deke";
            s.Phone  = "(029)85423657";
            s.Budget = 80000.0;

            //Restore saved state
            s.RestoreMemento(m.Memento);

            //Wait for user
            Console.Read();
        }