适配器和代理模式之间的确切区别是什么? [英] What is the exact difference between Adapter and Proxy patterns?

查看:468
本文介绍了适配器和代理模式之间的确切区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我所理解的适配器代理模式使两个不同/不同的类/对象与每个对象兼容以进行通信。而且它们都是结构模式。我得到的是,他们都是非常相似的。



有人可以解释一下他们是不同的吗?



编辑:
我经历了



您可以在此SE文章中找到有关此模式的更多详细信息:工作代码示例: p>



通常情况下代理模式适用。


  1. 虚拟代理是创建对象的占位符。实际的对象仅在客户端首次请求/访问对象时创建。

  2. 远程代理为位于不同地址的对象提供本地代理空间。这是RPC和CORBA提供的stub代码。

  3. 保护性代理控制对敏感主对象的访问。 代理对象检查呼叫者在转发请求之前是否具有所需的访问权限。

  4. 智能代理提供对某些对象(如跟踪)的复杂访问




$ b $ / p>对于工作代码,请查看 tutorialspoint 关于Proxy的文章。



主要区别:


  1. 适配器为其主题提供了不同的界面。代理提供相同的界面

  2. 适配器旨在更改现有对象的界面

您可以在代理中的源文章中找到有关这些模式的更多详细信息, a>和适配器文章。



其他有用的文章:代理由dzone


As I understood both Adapter and Proxy patterns make two distinct/different classes/objects compatible with each for communication. And both of them are Structural patterns. I am getting that both of them are pretty much similar with each other.

Can some one explain what exactly make(s) them different?

EDIT: I went through this question. But I'd rather like to have a close comparison between Adapter and Proxy.

解决方案

Adapter:

  1. It allows two unrelated interfaces to work together through the different objects, possibly playing same role.
  2. It modifies original interface.

UML diagram:

You can find more details about this pattern with working code example in this SE post:

Difference between Bridge pattern and Adapter pattern

Proxy:

Proxy provide a surrogate or place holder for another object to control access to it.

UML diagram:

There are common situations in which the Proxy pattern is applicable.

  1. A virtual proxy is a place holder for "expensive to create" objects. The real object is only created when a client first requests/accesses the object.
  2. A remote proxy provides a local representative for an object that resides in a different address space. This is what the "stub" code in RPC and CORBA provides.
  3. A protective proxy controls access to a sensitive master object. The "surrogate" object checks that the caller has the access permissions required prior to forwarding the request.
  4. A smart Proxy provides sophisticated access to certain objects such as tracking the number of references to an object and denying access if a certain number is reached, as well as loading an object from database into memory on demand

For working code, have a look at tutorialspoint article on Proxy.

Key differences:

  1. Adapter provides a different interface to its subject. Proxy provides the same interface
  2. Adapter is meant to change the interface of an existing object

You can find more details about these patterns in sourcemaking articles of proxy and adapter articles.

Other useful articles: proxy by dzone

这篇关于适配器和代理模式之间的确切区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆