代理模式学习笔记

Proxy Pattern

Intent

Provide a surrogate or placeholder for another object to control access to it.

代理模式为另一个对象提供替身或者占位符以控制对这个对象的访问.

 

使用代理模式创建代表(Representative)对象, 让代表对象控制对象的访问, 被代理的对象可以是远程的对象, 创建开销大的对象, 或需要安全控制的对象.

 

代理控制访问的方式:

l  远程代理控制访问远程对象

l  虚拟代理控制访问创建开销大的资源

l  保护代理基于权限控制对资源的访问

 

Applicability

Proxy is applicable whenever there is a need for a more versatile or sophisticated reference to a object than a simple pointer. Here are several common situations in which the Proxy pattern is applicable.

 

1.       A remote proxy provides a local representative for a object in a different address space. NEXTSTEP uses the class NXProxy for this purpose. Coplien calls this kind of proxy an “Ambassador”.

2.       A virtual proxy creates expensive objects on demand. The ImageProxy described in the Motivation is an example of such a proxy.

3.       A protection proxy control access to the original object. Protection proxies are useful when objects should have different access rights. For example, KernelProxies in the choices operating system provide protected access to operating system object.

4.       A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed. Typical uses include:

l  Counting the number of references to the real object so that it can be freed automatically when there are no more references( also called smart pointers).

l  Loading a persistent object object into memory when it’s first referenced.

l  Checking that real objects is locked before it’s accessed to ensure that no other object can change it.

 

Collaborations

Proxy forwards requests to RealSubject when appropriate, depending on the kind of proxy.

 

Consequences

The proxy pattern introduces a level of indirection when accessing a object. The additional indirection has many uses, depending on the kind of proxy:

1.       A remote proxy can hide the fact that an object resides in a different address space.

2.       A virtual proxy can perform optimizations such as creating a object on demand.

3.       Both protection proxies and smart references allow additional housekeeping tasks when an object is accessed.

Related Patterns

Adapter: An adapter provides a different interface to the object it adapts. In contrast, a proxy provides the same interface as its subject. However, a proxy used for access protection might refuse to perform an operation that the subject will perform, so its interface may be effectively a subset of the subject’s.

Decorator: Although decorators can have similar implementations as proxies, decorators have a different purpose. A decorator adds one or more responsibilities to an object, whereas a proxy controls access to an object. Proxies vary in the degree to which they are implemented like a decorator. A protection proxy might be implemented exactly like a decorator. On the other hand, a remote proxy will not contain a direct reference to its real subject but only an indirect reference, such as ‘host ID and local address on host’. A virtual proxy will start off with an indirect reference such as a file name but will eventually obtain and use a direct reference.

 

代理模式同其它模式的区别和联系

代理                                                                                                     装饰者

控制对象访问                                                                                  装饰对象

只传递请求不改变原来动作          在原来对象进行封装的基础上添加新的责任

远程代理不是封装而是传递请求

虚拟代理会延迟源对象的创建                            源对象的引用必须在封装前存在

 

代理                                                                                                     适配器

代理提供跟源对象同样的接口                            适配器提供了与它适配的对象不同的接口

代理控制对源对象的访问         适配器只是改变适配对象的访问接口, 没有加以控制

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

代码转载自:https://pan.quark.cn/s/a4b39357ea24 本文重点阐述了利用 LabVIEW 软件构建的锁相放大器的设计方案及其具体实施流程,并探讨了该设备在声波相位差定位系统中的实际运用情况。 锁相放大器作为一项基础测量技术,其核心功能在于能够精确锁定微弱信号的频率参数并完成相关测量工作。 在采用 LabVIEW 软件开发的锁相放大器系统中,通过计算测量信号与两条参考信号之间的互相关函数,实现对微弱信号的频率锁定,同时输出被测信号的幅值信息。 虚拟仪器技术是一种基于计算机硬件平台的仪器系统,其显著特征在于用户可以根据实际需求自主设计仪器功能,配备虚拟化操作界面,并将测试功能完全由专用软件程序实现。 虚拟仪器系统的基本架构主要由计算机主机、专用软件程序以及硬件接口模块等核心部件构成。 虚拟仪器最突出的优势在于其功能完全取决于软件编程,用户可以根据具体应用场景灵活调整系统功能参数。 在基于 LabVIEW 软件开发的锁相放大器系统中,主要运用 LabVIEW 软件平台完成锁相放大器功能的整体设计。 LabVIEW 作为一个图形化编程环境,能够高效地完成虚拟仪器的开发工作。 借助 LabVIEW 软件,可以快速构建锁相放大器的用户操作界面,并且可以根据实际需求进行灵活调整和功能扩展。 锁相放大器系统的关键构成要素包括测量信号输入通道、参考信号输入通道、频率锁定处理单元以及信号幅值输出单元。 测量信号是系统需要检测的对象,参考信号则用于引导系统完成对测量信号的频率锁定。 频率锁定处理单元负责实现测量信号的锁定功能,信号幅值输出单元则负责输出被测信号的幅值大小。 在锁相放大器的实际实现过程中,系统采用了双路参考信号输入方案来锁定测量信号。 通过分析两路参考信号之间的相...
边缘计算环境中基于启发式算法的深度神经网络卸载策略(Matlab代码实现)内容概要:本文介绍了在边缘计算环境中,利用启发式算法实现深度神经网络任务卸载的策略,并提供了相应的Matlab代码实现。文章重点探讨了如何通过合理的任务划分与调度,将深度神经网络的计算任务高效地卸载到边缘服务器,从而降低终端设备的计算负担、减少延迟并提高整体系统效率。文中涵盖了问题建模、启发式算法设计(如贪心策略、遗传算法、粒子群优化等可能的候选方法)、性能评估指标(如能耗、延迟、资源利用率)以及仿真实验结果分析等内容,旨在为边缘智能计算中的模型推理优化提供可行的技术路径。; 适合人群:具备一定编程基础,熟悉Matlab工具,从事边缘计算、人工智能、物联网或智能系统优化方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①研究深度神经网络在资源受限设备上的部署与优化;②探索边缘计算环境下的任务卸载机制与算法设计;③通过Matlab仿真验证不同启发式算法在实际场景中的性能表现,优化系统延迟与能耗。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注算法实现细节与仿真参数设置,同时可尝试复现并对比不同启发式算法的效果,以深入理解边缘计算中DNN卸载的核心挑战与解决方案。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值