ITeye博客

The Visitor Pattern Re-visited

13146489 · 2012-04-19 21:10 · 架构与模式 · 编程语言 · Markdown

原文地址: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’s the pattern that is best suited for visiting simple data structures with few different types, but visiting them with hundreds of visitors. 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.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。