public class ObjectStructure
{
private List<Element> elements = new ArrayList<Element>();
public void Attach(Element element)
{
elements.add(element);
}
public void Detach(Element element)
{
elements.remove(element);
}
public void Accept(Vistor vistor)
{
for(Element e : elements)
{
e.Accept(vistor);
}
}
}
package com.zcr.vistor;
public class VistorTest
{
public static void main(String[] args)
{
ObjectStructure o = new ObjectStructure();
o.Attach(new ConcreteElementA());
o.Attach(new ConcreteElementB());
ConcreteVistor1 v1= new ConcreteVistor1();
ConcreteVistor2 v2= new ConcreteVistor2();
o.Accept(v1);
o.Accept(v2);
}
}