コード例 #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();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Pizza largePizza = new LargePizza();

            largePizza = new CheeseDecorator(largePizza);
            largePizza = new HamDecorator(largePizza);

            Console.WriteLine("Pizza name: {0}, Pizza price: {1}", largePizza.GetName(), largePizza.CalculateCost());
            Console.ReadLine();
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            Pizza largePizza = new LargePizza();

            largePizza = new HamPizza(largePizza);
            largePizza = new CheesePizza(largePizza);

            Console.WriteLine("{0} costs {1}.", largePizza.GetDescription(), largePizza.CalculateCost());

            Console.ReadKey();
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            Pizza largePizza = new LargePizza();

            largePizza = new CheeseDecorator(largePizza);
            largePizza = new HamDecorator(largePizza);
            largePizza = new ChampignonsDecorator(largePizza);
            Console.WriteLine(largePizza.CalculateCost());
            Console.WriteLine(largePizza.GetName());
            Console.ReadLine();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Pizza largePizza = new LargePizza();

            largePizza = new ChesseDecorator(largePizza);
            largePizza = new HamDecorator(largePizza);

            Console.WriteLine(largePizza.GetDescription());
            Console.WriteLine("{0:C2}", largePizza.CalcullateCost());

            Console.ReadLine();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            Pizza largePizza = new LargePizza();

            largePizza = new CheeseDecorator(largePizza);
            largePizza = new JalapenoDecorator(largePizza);
            largePizza = new PepperoniDecorator(largePizza);


            Console.WriteLine(largePizza.GetDescription());
            Console.WriteLine("{0:C2}", largePizza.CalculateCost());

            Console.ReadKey();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: rezacse/DesignPatterns
        private static void Main()
        {
            Pizza largePizza = new LargePizza();

            largePizza = new Cheese(largePizza);
            largePizza = new Ham(largePizza);
            largePizza = new Peppers(largePizza);


            Console.WriteLine($"Pizza Description: {largePizza.GetDescription()}");
            Console.WriteLine($"Pizza Price: {largePizza.GetPrice()}");

            Console.ReadKey();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: strosu/Design-Patterns
        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();
        }
コード例 #9
0
        static void Main()
        {
            var regularPizza = new RegularPizza();

            Console.WriteLine(regularPizza.Info());

            var regularPizzaAndCheese = new Cheese(regularPizza);

            Console.WriteLine(regularPizzaAndCheese.Info());

            var largePizza = new LargePizza();

            Console.WriteLine(largePizza.Info());

            var largePizzaAndCheese = new Cheese(largePizza);

            Console.WriteLine(largePizzaAndCheese.Info());

            var largePizzaAndMushroomAndCheese = new Mushroom(largePizzaAndCheese);

            Console.WriteLine(largePizzaAndMushroomAndCheese.Info());
        }