internal AlcoholistMemento( Alcoholist originator) { name = originator.Name; consumption = originator.consumption; lastmodified = originator.LastModificationDate; this.originator = originator; }
public static void RestoreMemento(Alcoholist originator) { if (!Mementos.ContainsKey(originator)) { throw new InvalidOperationException("No memento."); } Mementos[originator].RestoreMemento(originator); }
internal void RestoreMemento(Alcoholist alc) { if (!alc.Equals(originator)) { throw new InvalidOperationException ("Invalid originator."); } alc.Name = name; alc.consumption = consumption; alc.LastModificationDate = lastmodified; }
public static void SaveMemento(Alcoholist originator) { if (Mementos.ContainsKey(originator)) { Mementos[originator] = Alcoholist.AlcoholistMemento.SaveMemento(originator); } else { Mementos.Add(originator, Alcoholist.AlcoholistMemento .SaveMemento(originator)); } }
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(); }
internal static AlcoholistMemento SaveMemento(Alcoholist alc) { return(new AlcoholistMemento(alc)); }