コード例 #1
0
        // The abstract Coffee class defines the functionality of Coffee implemented by decorator
        public void TestDecorater()
        {
            Coffee c = new SimpleCoffee();

            Console.WriteLine("Cost: " + c.GetCost() + "; Ingredients: " + c.GetIngredients());


            c = new Milk(c);
            Console.WriteLine("Cost: " + c.GetCost() + "; Ingredients: " + c.GetIngredients());

            c = new Sprinkles(c);
            Console.WriteLine("Cost: " + c.GetCost() + "; Ingredients: " + c.GetIngredients());

            c = new Whip(c);
            Console.WriteLine("Cost: " + c.GetCost() + "; Ingredients: " + c.GetIngredients());

            // Note that you can also stack more than one decorator of the same type
            c = new Sprinkles(c);
            Console.WriteLine("Cost: " + c.GetCost() + "; Ingredients: " + c.GetIngredients());
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Lydiasaurus/Personal
 static void Main(string[] args)
 {
     AbstractBeverageDecorator DarkRoast = new Beverage();
     AbstractBeverageDecorator Sprinkles = new Sprinkles(DarkRoast);
     ProduceReceipt(Sprinkles);
 }