Пример #1
0
        static void Main(string[] args)
        {
            //Step 1: Define some dishes, and how many of each we can make
            FreshSalad caesarSalad = new FreshSalad("Crisp romaine lettuce", "Freshly-grated Parmesan cheese", "House-made Caesar dressing");

            caesarSalad.Display();

            Pasta fettuccineAlfredo = new Pasta("Fresh-made daily pasta", "Creamly garlic alfredo sauce");

            fettuccineAlfredo.Display();

            Console.WriteLine("\nMaking these dishes available.");

            //Step 2: Decorate the dishes; now if we attempt to order them once we're out of ingredients, we can notify the customer
            Available caesarAvailable  = new Available(caesarSalad, 3);
            Available alfredoAvailable = new Available(fettuccineAlfredo, 4);

            //Step 3: Order a bunch of dishes
            caesarAvailable.OrderItem("John");
            caesarAvailable.OrderItem("Sally");
            caesarAvailable.OrderItem("Manush");

            alfredoAvailable.OrderItem("Sally");
            alfredoAvailable.OrderItem("Francis");
            alfredoAvailable.OrderItem("Venkat");
            alfredoAvailable.OrderItem("Diana");
            alfredoAvailable.OrderItem("Dennis"); //There won't be enough for this order.

            caesarAvailable.Display();
            alfredoAvailable.Display();

            Console.ReadKey();
        }
Пример #2
0
        static void Dish()
        {
            FreshSalad ceasarSalad = new FreshSalad(
                new Dictionary <string, string>
            {
                { "Greens", "Crispy romaine lettuce" },
                { "Cheese", "Freshly-grated Parmasan cheese" },
                { "Dressing", "House-made Caesar dressing" }
            }
                );

            Pasta fettuccineAlfredo = new Pasta(
                new Dictionary <string, string>
            {
                { "Pasta", "Fresh-made daily pasta" },
                { "Sauce", "Creamy garlic alfredo sauce" }
            }
                );

            Console.WriteLine(ceasarSalad);
            Console.WriteLine(fettuccineAlfredo);

            AvailableDecorator caesarAvailable  = new AvailableDecorator(ceasarSalad, 2);
            AvailableDecorator alfredoAvailable = new AvailableDecorator(fettuccineAlfredo, 3);

            caesarAvailable.OrderItem("Superman");
            caesarAvailable.OrderItem("Batman");

            alfredoAvailable.OrderItem("Wonder Women");
            alfredoAvailable.OrderItem("Plastic Man");
            alfredoAvailable.OrderItem("Flash");

            // not enough
            alfredoAvailable.OrderItem("Batman");

            Console.WriteLine(caesarAvailable);
            Console.WriteLine(alfredoAvailable);
        }