public void NotifyAboutNewBike(BikeModel model) { if (model.Type == BikeType.Road) { Console.WriteLine($" - The Road bike shop now sells the {model.Name}"); } }
public void NotifyShops(BikeModel model) { Console.WriteLine($"Announcing the new {model.Name} bike"); foreach (WeakReference <IBikeShop> shopRef in _shops.ToArray()) { // C# 6 allows an out parameter to be declare when it's first used shopRef.TryGetTarget(out IBikeShop shop); // The object has been destroyed so we don't want to // keep it in out list of observers if (shop == null) { UnregisterShop(shopRef); } else { shop.NotifyAboutNewBike(model); } } }