private static void InternalVisibilityApproach() { Console.WriteLine("Internal Visibility Approach"); SpeedometerInternalVisibility speedo = new SpeedometerInternalVisibility(); speedo.CurrentSpeed = 50; speedo.CurrentSpeed = 100; Console.WriteLine("Current speed: " + speedo.CurrentSpeed); Console.WriteLine("Previous speed: " + speedo.previousSpeed); // Save the state of 'speedo' SpeedometerMementoInternalVisibility memento = new SpeedometerMementoInternalVisibility(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 SpeedometerMementoInternalVisibility(SpeedometerInternalVisibility speedometer) { this.speedometer = speedometer; copyOfCurrentSpeed = speedometer.CurrentSpeed; copyOfPreviousSpeed = speedometer.previousSpeed; }