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

您没有登录

» Java开发网 » Design Pattern & UML  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Decorator and Proxy 的区别
MoutainHigh





发贴: 7
积分: 0
于 2005-03-25 17:15 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
虽然知道定义上他们的区别,但是我看了一些实现代码,怎么觉得很相似呢。
都是一个类A把另外一个类B给包起来,然后A call B的方法来实现。

我有些糊涂, 大家帮我解开迷雾吧!

谢谢。



作者 Re:Decorator and Proxy 的区别 [Re:MoutainHigh]
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2005-03-28 14:09 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
我说2句。。。怕说错了。。。说错了表打我

proxy做的事情很少,一般就是是延迟,缓存

decorator则是在别人的基础上,作更多的修饰

举例来说,proxy可以在显示大的图片的时候用(不好意思,举烂的例子了)
decorator则是。。比如swing里面,要给一个面板加滚动条,用的就是decorator模式



No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:Decorator and Proxy 的区别 [Re:MoutainHigh]
MoutainHigh





发贴: 7
积分: 0
于 2005-03-29 11:27 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
呵呵, 怎么敢打楼上的。
谢谢了。
你说的区别我也能理解,但是,总是不能一个本质的认识。
等以后用到了才深刻体会吧。
希望高手们多多发言,也算为中国的软件业赶超印度做些贡献。



作者 Re:Decorator and Proxy 的区别 [Re:MoutainHigh]
dissip

BigCat



发贴: 240
积分: 60
于 2005-04-13 17:24 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
英文的东西比较简单:直接从英文原意理解就最正确了
proxy:the agency, function, or office of a deputy who acts as a substitute for another
即proxy是一个替代品,他替代了原有的东西(当然也可以在经过适当处理后,再把请求发送给原物品,当然也可以做完全不同的事),proxy与原物品是不同的,proxy是主要的主动体,原物品最多是次要的被动体。
decorator: furnish with something ornamental
decorator不改变原物品的特性,但增加了一些装饰性的东西,decorator与原物品本质是相同的,原物品是主要的,decorator最多是些次要的装饰。
他们的差别关键在概念上,有时实现上的方式非常相似。
不是我说清楚了没有,:)



To live is to fight.

作者 Re:Decorator and Proxy 的区别 [Re:MoutainHigh]
popplelee





发贴: 1
积分: 0
于 2005-04-16 21:02 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
支持支持!!!
//入门中ING。。。



作者 Re:Decorator and Proxy 的区别 [Re:MoutainHigh]
hitaco





发贴: 432
积分: 31
于 2005-05-24 15:55 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
我记得GoF book中有这么一段,原文忘记了,大概意思:

很多pattern, 比如proxy和decorator, 他们的实现方式差不多,但最重要的是他们的intent不同,使用场合不同。



作者 Re:Decorator and Proxy 的区别 [Re:jigsaw]
jameszhang



CJSDN高级会员


发贴: 1594
积分: 111
于 2005-06-25 22:28 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
jigsaw wrote:
我说2句。。。怕说错了。。。说错了表打我

proxy做的事情很少,一般就是是延迟,缓存

decorator则是在别人的基础上,作更多的修饰

举例来说,proxy可以在显示大的图片的时候用(不好意思,举烂的例子了)
decorator则是。。比如swing里面,要给一个面板加滚动条,用的就是decorator模式

我可能跟你是一个老师教的!呵呵



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

Mahatma Gandhi"

作者 Re:Decorator and Proxy 的区别 [Re:MoutainHigh]
njluz





发贴: 18
积分: 0
于 2005-07-08 14:11 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
我感觉的理解模式,只看实现方式可能不能完全理解模式,楼主说的两个模式在实现上看起来其实真的很象,提一个细小差别,Decorator中包含对接口类型(Interface)的Reference,Proxy包括的是对实做(Implement Class)的Reference.
模式的使用有一个环境,目的,从这方面理解并且结合实现方式可能会更好理解模式.
Decorator目的将额外的责任动态的附加在对象上,不必演生新的子类及可弹性扩充功能,例如为文本编辑器添加边框,添加scrollbar,而不影响文本编辑器本身
Proxy目的替其他对象预留代理的空位,借此控制存取其他对象,例如图象等大对象的延迟载入,Remote Proxy,权限代理,智能型代理.
另外GoF的Design Pattern写的很好,建议详细阅读.



作者 Re:Decorator and Proxy 的区别 [Re:MoutainHigh]
ranchgirl



版主


发贴: 801
积分: 132
于 2005-12-19 01:12 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

Adapter provides a different interface to its subject. Proxy provides the same interface. Decorator provides an enhanced interface. [GOF. p216]

Decorator and Proxy have different purposes but similar structures. Both describe how to provide a level of indirection to another object, and the implementations keep a reference to the object to which they forward requests. [GOF, p220]





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