Exemple #1
0
        private static void approach1()
        {
            Console.WriteLine("APPROACH 1");
            Speedometer1 speedo = new Speedometer1();

            speedo.CurrentSpeed = 50;
            speedo.CurrentSpeed = 100;
            Console.WriteLine("Current speed: " + speedo.CurrentSpeed);
            Console.WriteLine("Previous speed: " + speedo.previousSpeed);

            // Save the state of 'speedo'
            SpeedometerMemento1 memento = new SpeedometerMemento1(speedo);

            // Change the state of 'speed'
            speedo.CurrentSpeed = 80;
            Console.WriteLine("After setting to 80...");
            Console.WriteLine("Current speed: " + speedo.CurrentSpeed);
            Console.WriteLine("Previous speed: " + speedo.previousSpeed);

            // Restore the state of 'speedo'
            Console.WriteLine("Now restoring state...");
            memento.RestoreState();
            Console.WriteLine("Current speed: " + speedo.CurrentSpeed);
            Console.WriteLine("Previous speed: " + speedo.previousSpeed);
        }
 public SpeedometerMemento1(Speedometer1 speedometer)
 {
     this.speedometer = speedometer;
     copyOfCurrentSpeed = speedometer.CurrentSpeed;
     copyOfPreviousSpeed = speedometer.previousSpeed;
 }
Exemple #3
0
 public SpeedometerMemento1(Speedometer1 speedometer)
 {
     this.speedometer    = speedometer;
     copyOfCurrentSpeed  = speedometer.CurrentSpeed;
     copyOfPreviousSpeed = speedometer.previousSpeed;
 }