设计模式学习19 Visitor

 应用场景:

在软件构建过程中,由于需求的变化,某些类层次常常需要新增加新的行为,如果直接改变基类的方法的话,将给子类的维护带来巨大的灾难。解决的思路是使用visitor模式,需要新增加方法的类是不需要改动的,只要实现相应的接口即可。这里是英文解释:

Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. 

实现代码:

posted @ 2010-07-24 19:51  qiang.xu  阅读(181)  评论(0编辑  收藏  举报