示例#1
0
 public void accept(ComputerPartVisitor cpVisitor)
 {
     for (int i = 0; i < _parts.Length; i++)
     {
         _parts[i].accept(cpVisitor);
     }
 }
示例#2
0
 public void accept(ComputerPartVisitor computerPartVisitor)
 {
     for (int i = 0; i < parts.Length; i++)
     {
         parts[i].accept(computerPartVisitor);
     }
     computerPartVisitor.visit(this);
 }
示例#3
0
 public void Accept(ComputerPartVisitor cpv)
 {
     foreach (var p in parts)
     {
         p.Accept(cpv);
     }
     cpv.Visit(this);
 }
示例#4
0
        /*
         * Behavioral Design Pattern
         * Here we have a Visitor and a Visitable.
         * Visitor has a visit method for each visitable.
         * Visitable has an accept method for the visitor.
         * This is particularly useful, say you're traversing through a Tree, and you want to handle leaf and various nodes differently. In this case, visitable are the leaves and nodes while the visitor has visit methods for each. So, when we come across a leaf, we let the leaf accept the visitor and then call the visitor's visit method. Hence, leaf just let's the visitor know about it's presence and let it take action accordinly.
         *
         */
        static void Main(string[] args)
        {
            var computer        = new Computer();
            var computerVisitor = new ComputerPartVisitor();

            computer.accept(computerVisitor);

            Console.ReadLine();
        }
示例#5
0
 public void accept(ComputerPartVisitor computerPartVisitor)
 {
     computerPartVisitor.visit(this);
 }
示例#6
0
 public void Accept(ComputerPartVisitor cpv)
 {
     cpv.Visit(this);
 }