Topic: visitor感觉有点麻烦,不如直接判断?

  Print this page

1.visitor感觉有点麻烦,不如直接判断? Copy to clipboard
Posted by: jameszhang
Posted on: 2004-12-17 16:50

visitor 模式 针对 Collection 中的对象处理,不如 直接处理对象来的方便,不知大家怎么看?

2.Re:visitor感觉有点麻烦,不如直接判断? [Re: jameszhang] Copy to clipboard
Posted by: justin_here
Posted on: 2004-12-17 20:10

就「個人經驗」,很少看到Visitor模式的應用。。。。

3.Re:visitor感觉有点麻烦,不如直接判断? [Re: jameszhang] Copy to clipboard
Posted by: emarket
Posted on: 2004-12-17 22:33

如果你接触过 用smalltallk的人写的代码,你就会发现发现你在visitor的海洋里面了。
smalltalk里面允许返回一段代码块, java里面很多人就用visitalbe去模拟这种代码段。

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

4.Re:visitor感觉有点麻烦,不如直接判断? [Re: jameszhang] Copy to clipboard
Posted by: jameszhang
Posted on: 2004-12-18 08:06

visitor应用前提是觉得原来的访问代码随着类型的增多会变常便复杂,可我怎么看,感觉visitor比原来的更长更复杂,呵呵

5.Re:visitor感觉有点麻烦,不如直接判断? [Re: jameszhang] Copy to clipboard
Posted by: emarket
Posted on: 2004-12-18 17:21

如果你的vistable们的结构相对 固定,你可以在不改 visitable 代码的基础上,增加visitor, 从而达到 extendable的目的。

6.Re:visitor感觉有点麻烦,不如直接判断? [Re: jameszhang] Copy to clipboard
Posted by: jameszhang
Posted on: 2004-12-18 22:31


7.Re:visitor感觉有点麻烦,不如直接判断? [Re: emarket] Copy to clipboard
Posted by: floater
Posted on: 2004-12-19 02:45

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.

8.Re:visitor感觉有点麻烦,不如直接判断? [Re: jameszhang] Copy to clipboard
Posted by: zyzhang
Posted on: 2004-12-20 20:21

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.


   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