Facade vs Proxy

[b]Question:[/b]
i feel there is not much difference between a facade and proxy pattern, and they can be exchanged for each other in some cases ., can someone provide light on the diffence in these patterns and when is facade more appropriate to using proxy.
For eg, in my FBN system, the controller talks to another object( facade or proxy or mediator ?) which talks to the data classes ? what is this class between the controller & data classes , proxy or facade ?

[b]Answer1:[/b]
A proxy can filter out bad requests, where as a facade doesn't filter anything, it justs acts as a way to make a complex subsystem easier to access for a client.
A proxy is a "Stand-in" it pretends to be the subsystem, taking requests and deciding if it is ok to really send it to the subsystem.
So while they are very much like "Fronts" for an underlying system, there really is two seperate purposes.
I always look at proxies, and think web server proxies to protect web servers for bad people.

[b]Answer2:[/b]
Proxies are a stand-in, Facades hide complexity.
Other uses for proxies are accessing remote resources like we are doing and deferring creation of expensive resources until they are actually needed.

[b]Answer3:[/b]
A proxy delegates to an instance of the same type as the proxy. A facade not.

[b]Answer4:[/b]
“Facade:用于隐藏调用的复杂性”
由于是隐藏复杂性,所以在Facade中就可能包含对后端组件、对象的接口访问,比如来自不同Domain的业务组件、跨专题的技术组件等。简单说,是对后端各接口的聚合,目的为了简化。
“Proxy:保护被访问的对象”
实际上就是控制对后端组件或对象的访问,而且是针对特定组件的访问控制。简单说,是对后端某类特定接口的访问代理

[list]
[Facade]
[/list]
[img]http://dl.iteye.com/upload/attachment/228304/956030ff-2189-3cf0-9565-f522fad245b0.png[/img]
Facade - 为调用方定义简单的调用接口
Clients - 调用者。通过Facade接口调用提供某功能的内部类群
Packages - 功能提供者。指提供功能的类群(模块或子系统)

[list]
[Proxy]
[/list]
[img]http://dl.iteye.com/upload/attachment/228301/6c5bfcbc-b450-3b35-86c2-e0e061ebef44.png[/img]

Subject -被代理的类的接口
Proxy 代理类 - 该代理类实现了Subject接口
RealSubject 代理元 - 即被代理的目标类,它实现了Subject接口
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值