命令模式与访客模式 [英] Command Pattern vs. Visitor Pattern
本文介绍了命令模式与访客模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
允许访问者修改接收者的状态通常是可以接受的,还是应该改为使用命令模式?
Is it generally acceptable to allow a Visitor to modify state of the Receiver, or should that be a Command pattern instead?
推荐答案
访问者模式的目的是允许将新操作添加到类继承结构中,而无需对该继承结构进行任何修改.我从未见过有人建议仅接受只读操作.唯一的限制是,添加的操作只能使用类继承关系的公共接口.
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.
这篇关于命令模式与访客模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文