I have a question about visitor pattern. What is not clear to me is what is the Object structure shown in the visitor design. from the GOF design pattern book:
ObjectStructure:
- can enumerate its elements.
- ObjectStructure: may provide a high-level interface to allow the visitor to visit its elements.
- ...
Does the second ponint mean I can add the accept method to the ObjectStructure class? [like in the code below]
class ObjectStructure{
private Collection<Element> collection;
public void accept(Visitor visitor){
for(Element element: collection)
element.accept(visitor);
}
}
Thank you.
Aucun commentaire:
Enregistrer un commentaire