Exemplo n.º 1
0
        //Component


        public void TestComposite()
        {
            // initialize variables
            var compositeGraphic  = new CompositeGraphic();
            var compositeGraphic1 = new CompositeGraphic();
            var compositeGraphic2 = new CompositeGraphic();

            //Add 1 Graphic to compositeGraphic1
            compositeGraphic1.Add(new Ellipse());

            //Add 2 Graphic to compositeGraphic2
            compositeGraphic2.AddRange(new Ellipse(),
                                       new Ellipse());

            /*Add 1 Graphic, compositeGraphic1, and
             * compositeGraphic2 to compositeGraphic */
            compositeGraphic.AddRange(new Ellipse(),
                                      compositeGraphic1,
                                      compositeGraphic2);

            /*Prints the complete graphic
             * (four times the string "Ellipse").*/
            compositeGraphic.Print();
            Console.ReadLine();
        }
        public static void Test()
        {
            //Initialize four ellipses
            var ellipse1 = new Ellipse("ellipse1");
            var ellipse2 = new Ellipse("ellipse2");
            var ellipse3 = new Ellipse("ellipse3");
            var ellipse4 = new Ellipse("ellipse4");

            //Initialize three composite graphics
            var graphic  = new CompositeGraphic("graphic");
            var graphic1 = new CompositeGraphic("graphic1");
            var graphic2 = new CompositeGraphic("graphic2");

            //Composes the graphics
            graphic1.Add(ellipse1);
            graphic1.Add(ellipse2);
            graphic1.Add(ellipse3);

            graphic2.Add(ellipse4);

            graphic.Add(graphic1);
            graphic.Add(graphic2);

            //Prints the complete graphic (four times the string "Ellipse").
            graphic.Print();
        }
Exemplo n.º 3
0
    static void Main(string[] args)
    {
        // Initialize variables
        var compositeGraphic1 = new CompositeGraphic();
        var compositeGraphic2 = new CompositeGraphic();
        var compositeGraphic3 = new CompositeGraphic();

        // Add 1 Graphic to compositeGraphic2
        compositeGraphic2.Add(new Ellipse());

        // Add 2 Graphic to compositeGraphic3
        compositeGraphic3.AddRange(new Ellipse(), new Circle());

        // Add 1 Graphic, compositeGraphic2, and  compositeGraphic3 to compositeGraphic1
        compositeGraphic1.AddRange(new Circle(), compositeGraphic2, compositeGraphic3);

        // Print the complete graphic
        compositeGraphic1.Print();

        Console.ReadKey();
    }
Exemplo n.º 4
0
    static void Main(string[] args)
    {
        // Initialize variables
        var compositeGraphic1 = new CompositeGraphic();
        var compositeGraphic2 = new CompositeGraphic();
        var compositeGraphic3 = new CompositeGraphic();

        // Add 1 Graphic to compositeGraphic2
        compositeGraphic2.Add(new Ellipse());

        // Add 2 Graphic to compositeGraphic3
        compositeGraphic3.AddRange(new Ellipse(), new Circle());

        // Add 1 Graphic, compositeGraphic2, and  compositeGraphic3 to compositeGraphic1
        compositeGraphic1.AddRange(new Circle(), compositeGraphic2, compositeGraphic3);

        // Print the complete graphic
        compositeGraphic1.Print();

        Console.ReadKey();
    }
Exemplo n.º 5
0
        private void compositePatternBtn_Click(object sender, RoutedEventArgs e)
        {
            // initialize variables
            var compositeGraphic  = new CompositeGraphic("Graphic");
            var compositeGraphic1 = new CompositeGraphic("Graphic1");
            var compositeGraphic2 = new CompositeGraphic("Graphic2");

            //Add 1 Graphic to compositeGraphic1
            compositeGraphic1.Add(new Ellipse(-8, -9, 10, 20));

            compositeGraphic1.AddRange(new Ellipse(35, 49, 35, 15),
                                       new Circle(5, 5, 37),
                                       new Rectangle(9, 8, 10, 10),
                                       new Square(-19, -23, 40));

            //Add 2 Graphic to compositeGraphic2
            compositeGraphic2.AddRange(new Ellipse(36, 74, 100, 135),
                                       new Ellipse(-1, -13, 25, 90));

            /*Add 1 Graphic, compositeGraphic1, and
             * compositeGraphic2 to compositeGraphic */
            compositeGraphic.AddRange(new Ellipse(0, 0, 23, 34),
                                      compositeGraphic1,
                                      new Circle(5, 5, 37),
                                      compositeGraphic2);

            compositeGraphic.AddRange(new Ellipse(55, 11, 30, 35),
                                      new Rectangle(10, 10, 20, 50),
                                      new Rectangle(5, 5, 30, 45),
                                      new Circle(5, 5, 37));

            /*Prints the complete graphic
             * (four times the string "Ellipse").*/
            compositeGraphic.Print();
            Console.ReadLine();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            if (exeCommandPattern)
            {
                string argument = args.Length > 0 ? args[0].ToUpper() : null;

                ISwitchable lamp = new Light();

                // Pass reference to the lamp instance to each command
                ICommand switchClose = new CloseSwitchCommand(lamp);
                ICommand switchOpen  = new OpenSwitchCommand(lamp);

                // Pass reference to instances of the Command objects to the switch
                Switch @switch = new Switch(switchClose, switchOpen);

                if (argument == "ON" || argument == "on")
                {
                    // Switch (the Invoker) will invoke Execute() on the command object.
                    @switch.Open();
                }
                else if (argument == "OFF" || argument == "off")
                {
                    // Switch (the Invoker) will invoke the Execute() on the command object.
                    @switch.Close();
                }
                else
                {
                    Console.WriteLine("Argument \"ON\" or \"OFF\" is required.");
                }
            }

            if (exeInterpretPattern)
            {
                var context = new Context();

                // Usually a tree
                var expression = new List <AbstractExpression>();

                // Populate 'abstract syntax tree'
                expression.Add(new TerminalExpression());
                expression.Add(new NonterminalExpression());
                expression.Add(new TerminalExpression());
                expression.Add(new TerminalExpression());

                // Interpret
                foreach (AbstractExpression exp in expression)
                {
                    exp.Interpret(context);
                }
            }

            if (exeCompositePattern)
            {
                // composite pattern
                var compositeGraphic  = new CompositeGraphic();
                var compositeGraphic1 = new CompositeGraphic();
                var compositeGraphic2 = new CompositeGraphic();

                compositeGraphic1.Add(new Ellipse());
                compositeGraphic2.AddRange(new Ellipse(), new Ellipse());

                compositeGraphic.AddRange(
                    new Ellipse(),
                    compositeGraphic1,
                    compositeGraphic2);

                compositeGraphic.Print();
                Console.ReadLine();
            }

            if (exeCompositeTerminalSymbol)
            {
                var bnfExpression = new CompositeTerminalSymbol("expression");
                var bnfPlus       = new CompositeTerminalSymbol("plus");
                var bnfMinus      = new CompositeTerminalSymbol("minus");
                var bnfVariable   = new CompositeTerminalSymbol("variable");
                var bnfDigit      = new CompositeTerminalSymbol("digit");
                var bnfNumber     = new CompositeTerminalSymbol("number");

                bnfExpression.AddRange(
                    new TerminalSymbol("plus"),
                    new TerminalSymbol("minus"),
                    new TerminalSymbol("variable"),
                    new TerminalSymbol("number"));

                bnfPlus.AddRange(bnfExpression, bnfExpression, new TerminalSymbol(" + "));
                bnfMinus.AddRange(bnfExpression, bnfExpression, new TerminalSymbol(" - "));
                bnfVariable.AddRange(
                    new TerminalSymbol("a"),
                    new TerminalSymbol("b"),
                    new TerminalSymbol("c"),
                    new TerminalSymbol("d"),
                    new TerminalSymbol("e"),
                    new TerminalSymbol("f"),
                    new TerminalSymbol("g")
                    );

                bnfDigit.AddRange(
                    new TerminalSymbol("0"),
                    new TerminalSymbol("1"),
                    new TerminalSymbol("2"),
                    new TerminalSymbol("3"),
                    new TerminalSymbol("4"),
                    new TerminalSymbol("5"),
                    new TerminalSymbol("6"),
                    new TerminalSymbol("7"),
                    new TerminalSymbol("8"),
                    new TerminalSymbol("9")
                    );

                bnfNumber.AddRange(bnfDigit, bnfDigit, bnfNumber);

                bnfExpression.Print(String.Empty);
                bnfPlus.Print(String.Empty);
                bnfMinus.Print(String.Empty);
                bnfVariable.Print(String.Empty);
                bnfDigit.Print(String.Empty);
                //bnfNumber.Print(string.Empty);

                Console.ReadLine();
            }
        }
Exemplo n.º 7
0
 public void Paint()
 {
     _compositeGraphic.Print();
 }