代理模式和虚拟代理模式的区别

发布于 2024-11-26 09:15:04 字数 238 浏览 4 评论 0原文

到目前为止,我知道代理模式,最近阅读了 this< /a> 文章说,虚拟代理基本上用于推迟内存密集型组件的对象创建过程,从而加快应用程序的速度。

但读完那篇文章后,看起来代理模式和虚拟代理模式是同一回事。我是对的还是我理解错了?

I knew of the proxy pattern till now and recently read this article that says a virtual proxy is basically used to defer the Object Creation process of memory-intensive components thereby speeding up the Application.

But after reading that article it looks like the proxy pattern and the virtual proxy pattern are the same thing. Am I right or have I understood this wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清醇 2024-12-03 09:15:04

有不同类型的代理模式。虚拟代理就是其中之一。其他(来自 GOF)是保护代理、远程代理、智能参考。来自 GOF:

远程代理为不同地址空间中的对象提供本地代表。

虚拟代理按需创建昂贵的对象。

保护代理控制对原始对象的访问。当对象应该具有不同的访问权限时,保护代理非常有用。

智能引用是裸指针的替代品,它在访问对象时执行附加操作

There are different types of proxy patterns. Virtual Proxy is one of them. Others (from GOF) are Protection Proxy, Remote Proxy, Smart Reference. From GOF:

A remote proxy provides a local representative for an object in a different address space.

A virtual proxy creates expensive objects on demand.

A protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights.

A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed

半夏半凉 2024-12-03 09:15:04

GoF 设计模式一书提到了几种代理,虚拟代理(按需创建昂贵的对象)就是其中之一。

其他类型的代理包括远程代理(为不同地址空间中的对象提供本地接口)、保护代理(处理访问权限)和智能引用(在访问对象时执行附加操作)。

因此,虽然虚拟代理肯定是代理,但并非所有代理都是虚拟的。

The GoF Design Patterns book mentions several kinds of proxies, the virtual proxy (which creates expensive objects on demand) being one of them.

Other types of proxies are remote proxy (which provides a local interface to an object in a different address space), protection proxy (which handles access rights) and smart reference (which performs additional actions when an object is accessed).

So while virtual proxies are definitely proxies, not all proxies are virtual.

潜移默化 2024-12-03 09:15:04

我们可以在创建自定义相机时使用虚拟代理模式。

想想如果一个页面中有3-4次点击capture_image的选项,那么每次点击capture_image时都创建相机对象并不好,因为初始化一个表面视图(在android中用于创建相机的视图)需要时间。因此,在这种情况下,我们可以使用虚拟代理模式来使用相同的实例,并在视图被销毁时销毁该相机对象。

We can use Virtual Proxy Pattern in case of creating Custom Camera.

Think about if there are 3-4 click option in a page to capture_image, it is not good to create camera object each and every time while we click on capture_image because initializing a surface view ( view used to create camera in android ) takes time. So we can use Virtual Proxy Pattern in this case to use same instance time-to-time and destroy this camera object when the view get destroyed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文