Esempio n. 1
0
        private void btnVisitor1_Click(object sender, EventArgs e)
        {
            txtResult.Text  = "VISITOR Pattern #1" + Environment.NewLine;
            txtResult.Text += "Some of the result is written to Output window" + Environment.NewLine;

            Element objectStructure =
                new Element(
                    new Element(
                        new ElementWithLink(
                            new Element(
                                new Element(
                                    new ElementWithLink(
                                        new Element(null),
                                        new Element(
                                            null)))),
                            new Element(
                                new Element(
                                    new Element(null))))));

            txtResult.Text += "Count the elements:" + Environment.NewLine;
            CountVisitor visitor = new CountVisitor();

            visitor.CountElements(objectStructure);
            txtResult.Text += "Number of Elements are: " + visitor.Count + Environment.NewLine;
        }
Esempio n. 2
0
        public void CountNumberOfElementsInObjectStructure()
        {
            var sut             = new CountVisitor();
            var objectStructure =
                new Element(
                    new Element(
                        new ElementWithLink(
                            new Element(new Element(new ElementWithLink(new Element(null), new Element(null)))),
                            new Element(new Element(new Element(null))))));


            sut.CountElements(objectStructure);

            Assert.That(sut.Count, Is.EqualTo(9), "elements");
        }
Esempio n. 3
0
        public static void Run()
        {
            // Set up the object structure
            Element objectStructure = new Element(new Element(new ElementWithLink(new Element(new Element(
                                                                                                  new ElementWithLink(new Element(null), new Element(null)))), new Element(new Element(new Element(null))))));

            Console.WriteLine("Count the Elements");
            CountVisitor visitor = new CountVisitor();

            visitor.CountElements(objectStructure);
            Console.WriteLine("Number of Elements is: " + visitor.Count);

            Console.WriteLine();
            Console.WriteLine("******************************************");
            Console.WriteLine();
        }
Esempio n. 4
0
        static void Demo()
        {
            // Set up the object structure
            Element objectStructure =
            new Element(
            new Element(
            new ElementWithLink(
            new Element(
            new Element(
            new ElementWithLink(
            new Element(null),
            new Element(
            null)))),
            new Element(
            new Element(
            new Element(null))))));

            Console.WriteLine("Count the Elements");
            CountVisitor visitor = new CountVisitor();
            visitor.CountElements(objectStructure);
            Console.WriteLine("Number of Elements is: " + visitor.Count);
        }