Ejemplo n.º 1
0
        private void decoratorPatternBtn_Click(object sender, RoutedEventArgs e)
        {
            CircleDecorator c = new CircleDecorator();

            Console.WriteLine(c.StrFunc());

            ColoredShape cc = new ColoredShape("red", c);

            Console.WriteLine(cc.StrFunc());

            // Create a decorated Window with horizontal and vertical scrollbars
            DPWindow decoratedWindow = new HorizontalScrollBarDecorator(
                new VerticalScrollBarDecorator(new SimpleWindow()));

            // Print the Window's description
            Console.WriteLine(decoratedWindow.GetDescription());

            Coffee kafica = new SimpleCoffee();

            Utils.printInfo(kafica);

            kafica = new WithMilk(kafica);
            Utils.printInfo(kafica);

            kafica = new WithSprinkles(kafica);
            Utils.printInfo(kafica);
        }
        public void CondimentDecorator_DecoratesCorrectly()
        {
            IBeverage           coffee = new SimpleCoffee();
            ICondimentDecorator order  = new Whip(coffee);

            Assert.AreEqual("Simple Black Coffee + Whip", order.Description);
        }
        public void CondimentDecorator_DecorateDescriptionIsValid()
        {
            IBeverage           coffee = new SimpleCoffee();
            ICondimentDecorator drink  = new Mocha(coffee);

            Assert.AreEqual("I am a mocha decorator", drink.DecoratorDescription);
        }
Ejemplo n.º 4
0
        public void CoffeeWithMilkCostlyThenSimpleCoffee()
        {
            var coffee         = new Mock <ICoffee>();
            var simpleCoffee   = new SimpleCoffee();
            var coffeeWithMilk = new WithMilk(simpleCoffee);

            Assert.IsTrue(coffeeWithMilk.Cost > simpleCoffee.Cost);
        }
        public void CondimentDecorator_DecoratesMultipleCorrectly()
        {
            string expectedOrderName = "Simple Black Coffee + Whip + Whip + Mocha + Milk + Soy";

            IBeverage           coffee = new SimpleCoffee();
            ICondimentDecorator order  = new Whip(coffee);

            order = new Whip(order);
            order = new Mocha(order);
            order = new Milk(order);
            order = new Soy(order);

            Assert.AreEqual(expectedOrderName, order.Description);
        }
        public void BeverageObjectDescription_ReturnsCorrectName()
        {
            IBeverage roast = new DarkRoast();

            Assert.AreEqual("Dark Roast Coffee", roast.Description);

            IBeverage coffee = new SimpleCoffee();

            Assert.AreEqual("Simple Black Coffee", coffee.Description);

            IBeverage espresso = new Espresso();

            Assert.AreEqual("Espresso", espresso.Description);
        }
Ejemplo n.º 7
0
    public static void Main(string[] args)
    {
        Coffee c = new SimpleCoffee();
          Console.WriteLine("Cost: " + c.getCost() + ";");

          c = new Milk(c);
          Console.WriteLine("Cost: " + c.getCost() + ";");

          c = new Sugar(c);
          Console.WriteLine("Cost: " + c.getCost() + ";");

          c = new SimpleCoffee();
          c = new Milk(new Sugar(c)); //shows the actual decoration
          Console.WriteLine("Cost: " + c.getCost() + ";");
    }
Ejemplo n.º 8
0
    public static void Main(string[] args)
    {
        Coffee c = new SimpleCoffee();

        Console.WriteLine("Cost: " + c.getCost() + ";");

        c = new Milk(c);
        Console.WriteLine("Cost: " + c.getCost() + ";");

        c = new Sugar(c);
        Console.WriteLine("Cost: " + c.getCost() + ";");

        c = new SimpleCoffee();
        c = new Milk(new Sugar(c)); //shows the actual decoration
        Console.WriteLine("Cost: " + c.getCost() + ";");
    }
Ejemplo n.º 9
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());
        }