//Note that the Restaurants will want to buy veggies if the price dips below a certain threshold //amount, which differs per restaurant. //To put this all together, in our Main method we can define a few restaurants that want to //observe the price of carrots, then fluctuate that price: static void Main(string[] args) { Carrots carrots = new Carrots(0.82); carrots.Attach(new Restaurant("Mackay's", 0.77)); carrots.Attach(new Restaurant("Johnny's Sports Bar", 0.74)); carrots.Attach(new Restaurant("Salad Kingdom", 0.75)); // Fluctuating carrot prices will notify subscribing restaurants. carrots.PricePerPound = 0.79; carrots.PricePerPound = 0.76; carrots.PricePerPound = 0.74; carrots.PricePerPound = 0.81; Console.ReadKey(); }
public static void Observer() { // Create price watch for Carrots and attach restaurants that buy carrots from suppliers. Carrots carrots = new Carrots(0.82); carrots.Attach(new Restaurant("Mackay's", 0.77)); carrots.Attach(new Restaurant("Johnny's Sports Bar", 0.74)); carrots.Attach(new Restaurant("Salad Kingdom", 0.75)); // Fluctuating carrot prices will notify subscribing restaurants. carrots.PricePerPound = 0.79; carrots.PricePerPound = 0.76; carrots.PricePerPound = 0.74; carrots.PricePerPound = 0.81; }
static void Main(string[] args) { Carrots carrots = new Carrots(0.82m); carrots.Attach(new HappyRestaurantVarna("Golden sands", 0.77m)); carrots.Attach(new HappyRestaurantVarna("Johnny's Sports Bar", 0.74m)); carrots.Attach(new HappyRestaurantVarna("Salad Kingdom", 0.75m)); // Fluctuating carrot prices will notify subscribing restaurants. carrots.PricePerPound = 0.79m; carrots.PricePerPound = 0.76m; carrots.PricePerPound = 0.74m; carrots.PricePerPound = 0.81m; Console.ReadKey(); }
/// <summary> /// Runners this instance. /// </summary> public void Runner() { ////carrot object is created and threshold value is set Carrots carrots = new Carrots(10.0); ////Attach is called with reference to carrot class and new object of restaurant is attached carrots.Attach(new Restaurant("Parmesh", 8.0)); ////Attach is called with reference to carrot class and new object of restaurant is attached carrots.Attach(new Restaurant("Manju", 7.5)); ////Attach is called with reference to carrot class and new object of restaurant is attached carrots.Attach(new Restaurant("Manoj", 7.9)); ////fluctutating pattern is set so that restaurant come in action if price ////is less than their threshold only then restaurant will notify that i want to buy carrots.PricePerKg = 6.0; carrots.PricePerKg = 11.0; }
static void Main(string[] args) { double[] pricePerDay = new double[] { 0.6, 0.5, 0.75, 0.3, 0.82 }; Carrots carrots = new Carrots(pricePerDay[0]); carrots.Attach(new Restaurant("Sam's Steakhouse", 0.5)); carrots.Attach(new Restaurant("Il Theatro", 0.7)); carrots.Attach(new Restaurant("Kürnberghalle", 0.4)); carrots.Attach(new Restaurant("XXXLutz", 0.8)); for (int i = 1; i < pricePerDay.Length; i++) { Console.WriteLine($"--> New Price: {pricePerDay[i]}"); carrots.PricePerPound = pricePerDay[i]; } }
static void Main(string[] args) { #region Veggies // Create price watch for Carrots and attach restaurants that buy carrots from suppliers. Carrots carrots = new Carrots(0.82); carrots.Attach(new Restaurant("Mackay's", 0.77)); carrots.Attach(new Restaurant("Johnny's Sports Bar", 0.74)); carrots.Attach(new Restaurant("Salad Kingdom", 0.75)); // Fluctuating carrot prices will notify subscribing restaurants. carrots.PricePerPound = 0.79; carrots.PricePerPound = 0.76; carrots.PricePerPound = 0.74; carrots.PricePerPound = 0.81; Console.ReadKey(); #endregion #region Newspaper // Create news agencies (providers). var associatedPress = new Agency("Associated Press"); var reuters = new Agency("Reuters"); // Create newspapers (observers). var newYorkTimes = new NewspaperClass("The New York Times"); var washingtonPost = new NewspaperClass("The Washington Post"); // AP publication. Neither newspaper subscribes, so no output. associatedPress.Publish("Waiting the worst with Harvey, the storm that won’t go away", "Juliet Linderman"); // Times subscribes to AP. newYorkTimes.Subscribe(associatedPress); // Post subscribes to Reuters. washingtonPost.Subscribe(reuters); // Reuters publications. reuters.Publish("Japan retail sales slow in July, still top expectations", "Stanley White"); reuters.Publish("Transgender members in U.S. military may serve until study completed: Mattis", "Reuters Staff"); // AP publications. associatedPress.Publish("Chicago changes course, wants police reforms with court role", "Don Babwin and Michael Tarm"); associatedPress.Publish("US Open fashion: Crystals, shapes and knee-high socks", "James Martinez"); // Post subscribes to AP. washingtonPost.Subscribe(associatedPress); // AP Publications, both Times and Post should receive. associatedPress.Publish("Game of Thrones: Trust me, I’m a Targaryen", "Paul Wiseman, Josh Boak, and Christopher Rugaber"); associatedPress.Publish("Merkel: Europe still ‘hasn’t done homework’ on refugees", "Geir Moulson"); // Post unsubscribes from AP. washingtonPost.Unsubscribe(associatedPress); // AP publication, should only be picked up by Times. associatedPress.Publish("Hajj pilgrimage entangled in web of Saudi politics", "Aya Batrawy"); // Perform cleanup for AP. associatedPress.Shutdown(); // Few more Reuters publications. reuters.Publish("Google, Apple face off over augmented reality technology", "Stephen Nellis"); reuters.Publish("Under investor pressure, Goldman to explain trading strategy", "Olivia Oran"); reuters.Publish("UK retailers see Brexit hit to consumers without detailed customs plans", "Reuters Staff"); Console.ReadKey(); #endregion }