예제 #1
0
 internal AlcoholistMemento(
     Alcoholist originator)
 {
     name            = originator.Name;
     consumption     = originator.consumption;
     lastmodified    = originator.LastModificationDate;
     this.originator = originator;
 }
예제 #2
0
 public static void RestoreMemento(Alcoholist originator)
 {
     if (!Mementos.ContainsKey(originator))
     {
         throw new InvalidOperationException("No memento.");
     }
     Mementos[originator].RestoreMemento(originator);
 }
예제 #3
0
 internal void RestoreMemento(Alcoholist alc)
 {
     if (!alc.Equals(originator))
     {
         throw new InvalidOperationException
                   ("Invalid originator.");
     }
     alc.Name                 = name;
     alc.consumption          = consumption;
     alc.LastModificationDate = lastmodified;
 }
예제 #4
0
 public static void SaveMemento(Alcoholist originator)
 {
     if (Mementos.ContainsKey(originator))
     {
         Mementos[originator] = Alcoholist.AlcoholistMemento.SaveMemento(originator);
     }
     else
     {
         Mementos.Add(originator,
                      Alcoholist.AlcoholistMemento
                      .SaveMemento(originator));
     }
 }
예제 #5
0
        static void Main(string[] args)
        {
            Alcoholist barney = new Alcoholist("Barney");

            AlcoholistMementoStore.SaveMemento(barney);
            Console.WriteLine(barney);

            barney.Consumption += 30;

            System.Threading.Thread.Sleep(500);

            Console.WriteLine(barney);

            AlcoholistMementoStore.RestoreMemento(barney);
            Console.WriteLine(barney);


            Console.ReadLine();
        }
예제 #6
0
 internal static AlcoholistMemento SaveMemento(Alcoholist alc)
 {
     return(new AlcoholistMemento(alc));
 }