Is it generally acceptable to allow a Visitor to modify state of the Receiver, or should that be a Command pattern instead?
+2
A:
I don't think you can make a blanket statement whether it's good or bad to modify state of anything. I would think it's ok to modify the states as long as it does not affect the visiting logic itself. For example, you might write a visitor that visits all files under folder structure and renames the file name to upper case.
eed3si9n
2010-05-18 14:05:04
+1
A:
The purpose of the visitor pattern is to allow new operations to be added to a class heirarchy without modification to that heirarchy. I've never seen anyone suggesting that only read-only operations are acceptable. The only limitation is that the added operations should only use the public interface of the class heirarchy.
Mark Nelson
2010-05-18 14:11:42