We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
谷歌是你的朋友。
http://www.javaworld.com/javatips/jw-javatip98.html :通常 JavaWorld 有好东西
http://en.wikipedia.org/wiki/Visitor_pattern#Java_example< /a>:甚至维基百科条目也有您可能正在寻找的 Java 示例。
Google is your friend.
http://www.javaworld.com/javatips/jw-javatip98.html: And usually JavaWorld has good stuff
http://en.wikipedia.org/wiki/Visitor_pattern#Java_example: And even the wikipedia entry has a Java example that you're probably looking for.
您可以在 Joshua Kerievsky 的“重构为模式”中找到对访问者模式的精彩描述。
里面给出的例子让一切都清楚了。但这本书并不是免费提供的。
You can find an excellent description of visitor pattern in "Refactoring to Patterns" of Joshua Kerievsky.
The example given in it makes everything clear. The book is not freely available though.
我在互联网上研究了很多关于这种模式的信息。
我了解到这种模式有多种风格。
特别是,我看到了很多令人困惑的实现,我决定更多地考虑它并设计一些我认为可以接受的实现方式。
我使用 Java 中的一个大型且复杂的库,该库以非常干净整洁的方式广泛使用访问者模式。特别是,我不喜欢使用 VisitA、visitB、visitWhatever、acceptA、acceptB、acceptWhatever 的实现。恕我直言,这是绝对错误的。你不需要这个。如果你把一切都保持整洁,你就可以将关心的事情分到各自的班级上,你的生活会更幸福。
如果有机会,请看一下 一篇文章我已经写过相关内容。
干杯
I've researched a lot in the Internet about this pattern.
I've learned that there are several flavors of this pattern.
In particular, I've seen so many confused implementations which I decided to think more about it and design something which I could consider acceptable for my purposes.
I work with a large and complex library in Java which extensively uses the Visitor Pattern in a very clean and neat way. In particular, I don't like implementations with visitA, visitB, visitWhatever, acceptA, acceptB, acceptWhatever. This is absolutely wrong, IMHO. You don't need this. If you keep everything neat, you can have concerns separated on their respective classes and your life will be much happier.
If you have a chance, please have a look at an article I've written about this.
Cheers