---
title: "The Visitor Pattern Re-visited"
author: "13146489"
date: "2012-04-19T21:10:09Z"
tags: []
categories: ["编程语言"]
slug: "the-visitor-pattern-re-visited"
draft: false
lastmod: "2012-04-19T21:10:09Z"
id: 1490768
url: "https://13146489.iteye.com/blog/1490768"
---

原文地址：<http://java.dzone.com/articles/visitor-pattern-re-visited>
Understanding the problem
The actual problem is not the naming and horrible API verbosity of visiting code, but the mis-understanding of the pattern. It’s not a pattern that is best suited for visiting large and complex data structures with lots of objects of different types. It<span style="color:red">’s the pattern that is best suited for visiting simple data structures with few different types, but visiting them with hundreds of visitors.</span> Take files and folders. That’s a simple data structure. You have two types. One can contain the other, both share some properties. Various visitors could be:

CalculateSizeVisitor
FindOldestFileVisitor
DeleteAllVisitor
FindFilesByContentVisitor
ScanForVirusesVisitor
… you name it
I still dislike the naming, but the pattern works perfectly in this paradigm.