コード例 #1
0
        public IActionResult Index()
        {
            var pizza  = new LargePizza();
            var cheese = new CheeseDecorator(pizza);
            var tomato = new TomatoDecorator(cheese);

            return(Content($"Decorato Pattern Pizza: {tomato.GetDescription()} - {tomato.CalculateCost()}"));
        }
コード例 #2
0
        public static string Run()
        {
            Pizza largePizza = new LargePizza();

            // wrap large pizza with our cheese decorator
            largePizza = new Cheese(largePizza);

            // wrap our large cheese pizza with our ham decorator
            largePizza = new Ham(largePizza);

            return($"{largePizza.GetDescription()} cost: {largePizza.CalculateCost():C2}");
        }
コード例 #3
0
        static void Main()
        {
            Pizza largePizza = new LargePizza();

            //Adding Cheese to Large Pizza
            largePizza = new Cheese(largePizza);

            //Adding Ham to Large Pizza
            largePizza = new Ham(largePizza);

            //Adding Peppers to Large
            largePizza = new Peppers(largePizza);

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