Esempio n. 1
0
        static void Main(string[] args)
        {
            Beverage bev = new AfricanBlend();

            Console.WriteLine(
                String.Format("{0} - ${1}",
                              bev.GetDescription(),
                              bev.GetCost()));

            bev = new HouseBlend();
            Console.WriteLine(
                String.Format("{0} - ${1}",
                              bev.GetDescription(),
                              bev.GetCost()));

            bev = new Cream(bev);
            Console.WriteLine(
                String.Format("{0} - ${1}",
                              bev.GetDescription(),
                              bev.GetCost()));

            bev = new Cream(bev);
            Console.WriteLine(
                String.Format("{0} - ${1}",
                              bev.GetDescription(),
                              bev.GetCost()));

            // We'll decorate an interface rather than an abstract base class
            IPizza pizza = new LargePizza();

            Console.WriteLine(
                String.Format("{0} - ${1}",
                              pizza.GetDescription(),
                              pizza.CalculateCost()));

            IPizza cheese = new Cheese(pizza);

            Console.WriteLine(
                String.Format("{0} - ${1}",
                              cheese.GetDescription(),
                              cheese.CalculateCost()));

            IPizza extra = new Cheese(cheese);

            Console.WriteLine(
                String.Format("{0} - ${1}",
                              extra.GetDescription(),
                              extra.CalculateCost()));

            IPizza sausage = new Sausage(extra);

            Console.WriteLine(
                String.Format("{0} - ${1}",
                              sausage.GetDescription(),
                              sausage.CalculateCost()));

            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Pizza pizza = new LargePizza();

            pizza = new Cheese(pizza);
            pizza = new Pineapple(pizza);

            Pizza pizza2 = new LargePizza().WithCheese().WithPineapple();

            Console.WriteLine(pizza.GetDescription());
            Console.WriteLine(pizza.GetPrice());

            Console.WriteLine(pizza2.GetDescription());
            Console.WriteLine(pizza2.GetPrice());

            Console.ReadLine();
        }