欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Facade vs Proxy 博客分类: Design Pattern WebAccess

程序员文章站 2024-02-27 22:43:09
...
Question:
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 ?

Answer1:
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.

Answer2:
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.

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

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


    [Facade]

Facade vs Proxy
            
    
    博客分类: Design Pattern WebAccess
Facade - 为调用方定义简单的调用接口
Clients - 调用者。通过Facade接口调用提供某功能的内部类群
Packages - 功能提供者。指提供功能的类群(模块或子系统)


    [Proxy]

Facade vs Proxy
            
    
    博客分类: Design Pattern WebAccess

Subject -被代理的类的接口
Proxy 代理类 - 该代理类实现了Subject接口
RealSubject 代理元 - 即被代理的目标类,它实现了Subject接口

  • Facade vs Proxy
            
    
    博客分类: Design Pattern WebAccess
  • 大小: 2.7 KB
  • Facade vs Proxy
            
    
    博客分类: Design Pattern WebAccess
  • 大小: 10.8 KB
相关标签: Web Access