While studying the visitor design pattern i found this phrase:
You can use Visitor along with Iterator to traverse a complex data structure and execute some operation over its elements, even if they all have different classes.
Visitor design pattern
While searching on the internet if it was a good idea I found different opinions. Some said that you can combine the two patterns:
You can perfectly combine both: use an iterator to move over each item of a data structure and pass a visitor to each item so that an external responsible performs some operation of the item.
iterator vs visitor
Others said that you can but it depends on the complexity of the operation:
The Visitor is not as such “unneeded” if you have an Iterator. It depends on the complexity of the operation(s) you want to apply to the items you are iterating over.
iterator and visitor
I am wondering in which situation it is useful to have such a combination of patterns. What kind of operation is considered complex ?
3