Exemplo n.º 1
0
 /// <summary>
 /// Notify an event to registered observers
 /// </summary>
 /// <param name="vehicle"></param>
 /// <param name="garageEvent"></param>
 public void Notify(Vehicle vehicle, GarageEnums.Events garageEvent)
 {
     foreach (var observer in Observers)
     {
         if (observer.Value == garageEvent)
         {
             observer.Key.Notify(vehicle, garageEvent);
         }
     }
 }
Exemplo n.º 2
0
        public void Notify(Vehicle vehicle, GarageEnums.Events garageEvent)
        {
            switch (garageEvent)
            {
            case GarageEnums.Events.AddVehicle:
                Console.WriteLine($"A new {vehicle.GetType().Name.ToLower()} has been added to the parc.");
                break;

            case GarageEnums.Events.RemoveVehicle:
                Console.WriteLine($"A {vehicle.GetType().Name.ToLower()} has been removed from the parc.");
                break;

            case GarageEnums.Events.Nothing:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(garageEvent), garageEvent, null);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Detach an observer
 /// </summary>
 /// <param name="observer"></param>
 /// <param name="garageEvent"></param>
 public void Detach(IObserver observer, GarageEnums.Events garageEvent)
 {
     Observers.Remove(new KeyValuePair <IObserver, GarageEnums.Events>(observer, garageEvent));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Attach an observer
 /// </summary>
 /// <param name="observer"></param>
 /// <param name="garageEvent"></param>
 public void Attach(IObserver observer, GarageEnums.Events garageEvent)
 {
     Observers.Add(new KeyValuePair <IObserver, GarageEnums.Events>(observer, garageEvent));
 }