예제 #1
0
        static void Main(string[] args)
        {
            // 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();
        }
예제 #2
0
        private static void Main()
        {
            // 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.SetPricePerPound(0.79);
            Console.WriteLine();

            carrots.SetPricePerPound(0.76);
            Console.WriteLine();

            carrots.SetPricePerPound(0.74);
            Console.WriteLine();

            carrots.SetPricePerPound(0.81);
            Console.WriteLine();
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Create price watch for Carrots and attach restaurants that buy carrots from suppliers.
            Carrots carrots = new Carrots(0.82);

            carrots.AddObserver(new Restaurant("Bubbles", 0.99, carrots));
            carrots.AddObserver(new Restaurant("Johns", 0.75, carrots));
            carrots.AddObserver(new Restaurant("Steve's'", 0.77, carrots));

            Broccoli    broccoli = new Broccoli(.75);
            IRestaurant bubbles  = new Restaurant("Bubbles", .99, broccoli);

            broccoli.AddObserver(bubbles);
            broccoli.PricePerPound = .45;


            // Fluctuating carrot prices will notify subscribing restaurants.
            carrots.PricePerPound = .77;
            carrots.PricePerPound = .50;
            carrots.PricePerPound = 10;
            carrots.PricePerPound = .84;

            Console.ReadLine();
        }