//客户端代码 static void Main(string[] args) { ObjectStrcture o = new ObjectStrcture(); o.Attach(new ConcreteElementA()); o.Attach(new ConcreteElementB()); ConcreteVisitor1 v1 = new ConcreteVisitor1(); ConcreteVisitor2 v2 = new ConcreteVisitor2(); o.Accept(v1); o.Accept(v2); }
static void Main(string[] args) { ObjectStructure o = new ObjectStructure(); o.Attach(new ConcreteElementA()); o.Attach(new ConcreteElementB()); ConcreteVisitor1 v1 = new ConcreteVisitor1(); ConcreteVisitor2 v2 = new ConcreteVisitor2(); o.Accept(v1); o.Accept(v2); Console.Read(); }
static void Main(string[] args) { ObjectStructure objectStructure = new ObjectStructure(); objectStructure.Add(new ConcreteElement1()); objectStructure.Add(new ConcreteElement2()); Visitor visitor = new ConcreteVisitor1(); objectStructure.accept(visitor); visitor = new ConcreteVisitor2(); objectStructure.accept(visitor); Console.Read(); }