Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Design Pattern & UML  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 visitor感觉有点麻烦,不如直接判断?
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2004-12-17 16:50 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
visitor 模式 针对 Collection 中的对象处理,不如 直接处理对象来的方便,不知大家怎么看?


"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"

作者 Re:visitor感觉有点麻烦,不如直接判断? [Re:jameszhang]
justin_here

良葛格



发贴: 72
积分: 96
于 2004-12-17 20:10 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
就「個人經驗」,很少看到Visitor模式的應用。。。。


http://caterpillar.onlyfun.net/

作者 Re:visitor感觉有点麻烦,不如直接判断? [Re:jameszhang]
emarket

亢龙有诲

CJSDN高级会员


发贴: 460
积分: 82
于 2004-12-17 22:33 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如果你接触过 用smalltallk的人写的代码,你就会发现发现你在visitor的海洋里面了。
smalltalk里面允许返回一段代码块, java里面很多人就用visitalbe去模拟这种代码段。

不过我是很讨厌这种code的, 不过如果真的需要用到 double dispach , 并且 visitable的结构相对固定,你还是可以引入visitor的。 不过至今为止 我还没有见到过这种requirement。 实际当中应该尽量减少这种代码。



个人Blog http://agilespeaking.blogspot.com/

作者 Re:visitor感觉有点麻烦,不如直接判断? [Re:jameszhang]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2004-12-18 08:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
visitor应用前提是觉得原来的访问代码随着类型的增多会变常便复杂,可我怎么看,感觉visitor比原来的更长更复杂,呵呵


"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"

作者 Re:visitor感觉有点麻烦,不如直接判断? [Re:jameszhang]
emarket

亢龙有诲

CJSDN高级会员


发贴: 460
积分: 82
于 2004-12-18 17:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如果你的vistable们的结构相对 固定,你可以在不改 visitable 代码的基础上,增加visitor, 从而达到 extendable的目的。


个人Blog http://agilespeaking.blogspot.com/

作者 Re:visitor感觉有点麻烦,不如直接判断? [Re:jameszhang]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2004-12-18 22:31 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list



"First they ignore u, then they laugh at u, then they fight u, then u will win

Mahatma Gandhi"

作者 Re:visitor感觉有点麻烦,不如直接判断? [Re:emarket]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-12-19 02:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
emarket wrote:
如果你的vistable们的结构相对 固定,你可以在不改 visitable 代码的基础上,增加visitor, 从而达到 extendable的目的。

This is the key.

For example, when you design a middleware lib, you should keep this in mind so that users of your lib can extend their own functionalities without changing your code(They don't know your code, they don't own your code, or they don't have the commercial right to do so). That means you could have a simple Visitable interface so users could tap into.



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code
作者 Re:visitor感觉有点麻烦,不如直接判断? [Re:jameszhang]
zyzhang

Explorer



发贴: 155
积分: 30
于 2004-12-20 20:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Actually, Visitor design pattern is very powerful if you can fit them in the right problem context. you can find loads of places(apache, middleware, xml utilities, and etc) using the idea behind visitor design pattern.

I used to using the combination of Composite and Visitor to tranverse tree-like data structure and adding the required handling methods in seperate visitor classes. It can help you gain the advantage of clean (distributing the responsibility), flexible and extensible design objectives.




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923