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; }
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"); }
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(); }
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); }