谁能指导我一篇描述访问者设计模式的优秀文章

发布于 2024-10-04 11:40:06 字数 1539 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

负佳期 2024-10-11 11:40:06

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.

π浅易 2024-10-11 11:40:06

您可以在 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.

苹果你个爱泡泡 2024-10-11 11:40:06

我在互联网上研究了很多关于这种模式的信息。
我了解到这种模式有多种风格。

特别是,我看到了很多令人困惑的实现,我决定更多地考虑它并设计一些我认为可以接受的实现方式。

我使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文