22-Visitor
The assumption is that you have a primary class hierarchy that is fixed; perhaps it’s from another vendor and you can’t make changes to that hierarchy. However, you’d like to add new polymorphic methods to that hierarchy, which means that normally you’d have to add something to the base class interface. So the dilemma is that you need to add methods to the base class, but you can’t touch the base class. How do you get around this?
The design pattern that solves this kind of problem is called a “visitor”......
以上是教材的提示部分,然后就是一个例子,我没有深入看,感觉没有多少指示作用,找了一个实例 ,感觉不错,但还不是很满意!主要是没有搞明白那个类是primary class hierarchy构成部分!看来这个visitor模式不是很好理解,好在发现了一个实际应用:dom4j 中的Visitor设计模式有应用支持,这个在后期再仔细消化吧!
上一篇: Java高级工程师面试题总结及参考答案
下一篇: 精选臭事爆笑四则
推荐阅读