コード例 #1
0
        static void Main(string[] args)
        {
            Pizza p = new Ham(new Cheese(new LargePizza())); // L


            Console.WriteLine(p.GetDescription());
            Console.WriteLine(p.CalculateCost());
            Console.ReadKey();
        }
コード例 #2
0
        public void Allow_Being_Decorated_With_Cheese_And_Ham()
        {
            Pizza largePizza = new LargePizza();

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

            Assert.Equal("Large Pizza, Cheese, Ham", largePizza.GetDescription());
            Assert.Equal(11.25m, largePizza.CalculateCost());
        }
コード例 #3
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}");
        }
コード例 #4
0
        public static void Bake()
        {
            Pizza pizza = new LargePizza();

            Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}");
            pizza = new Ham(pizza);
            Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}");
            pizza = new Cheese(pizza);
            Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}");
            pizza = new Corn(pizza);
            Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}");
            pizza = new Cheese(pizza);
            Console.WriteLine($"{pizza.CalculateCost()}EUR for {pizza.GetDescription()}");
        }