设计模式18 - 访问者模式

1. 简介

访问者者模式的英文翻译是 Visitor Design Pattern。

在 GoF 的《设计模式》一书中,它是这么定义的:

Allows for one or more operation to be applied to a set of objects at runtime, decoupling the operations from the object structure.

翻译成中文就是:

允许一个或者多个操作应用到一组对象上,解耦操作和对象本身。

对于访问者模式的代码实现,实际上,在上面例子中,经过层层重构之后的最终代码,就是标准的访问者模式的实现代码。这里,我又总结了一张类图,贴在了下面,你可以对照着前面的例子代码一块儿来看一下

设计模式18 - 访问者模式_第1张图片

你可能感兴趣的:(设计模式)