概述
The Visitor pattern allows to apply one or more operation to a set of objects at run-time without having the operations tightly coupled with the object structure.
Visitor模式是指通过封装一个对象实现聚合列表中每个元素的操作(访问)。
访问者(Visitor)模式的定义:将作用于某种数据结构中的各元素的操作分离出来封装成独立的类,使其在不改变数据结构的前提下可以添加作用于这些元素的新的操作,为数据结构中的每个元素提供多种访问方式。它将对数据的操作与数据结构进行分离,是行为类模式中最复杂的一种模式。
本文类图

主要代码



测试结果

网友评论