首页 \ 问答 \ 何时使用“动态代理类”或“标准代理”模式?(When to use “Dynamic Proxy class” or “standard proxy” pattern?)

何时使用“动态代理类”或“标准代理”模式?(When to use “Dynamic Proxy class” or “standard proxy” pattern?)

为什么要使用“动态代理类”而不是“标准代理”模式?

两者的缺点或优点是什么?

看起来它们都有相同的最终结果,除了它们的实现方式不同。

动态代理类https://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html

动态代理类是实现在运行时指定的接口列表的类,这样通过类的实例上的一个接口的方法调用将被编码并通过统一接口分派给另一个对象。 因此,动态代理类可用于为接口列表创建类型安全的代理对象,而无需预生成代理类,例如使用编译时工具。 动态代理类实例上的方法调用被分派到实例的调用处理程序中的单个方法,并使用标识被调用方法的java.lang.reflect.Method对象和包含该方法的Object类型数组进行编码。参数。

标准代理模式https://en.wikipedia.org/wiki/Proxy_pattern

代理以其最一般的形式,是一个充当其他东西的接口的类。 代理可以与任何东西连接:网络连接,内存中的大对象,文件或其他昂贵或无法复制的资源。 简而言之,代理是一个包装器或代理对象,客户端正在调用它来访问幕后的真实服务对象。 在代理中,可以提供额外的功能,例如当真实对象上的操作是资源密集时的高速缓存,或者在调用真实对象上的操作之前检查先决条件。 对于客户端,代理对象的使用类似于使用真实对象,因为两者都实现相同的接口。


Why should one use a "Dynamic Proxy class" instead of the "standard proxy" pattern?

What are the disadvantages or advantages of both?

It seems like they both have the same end result, except that they are implemented differently.

Dynamic proxy class https://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html

A dynamic proxy class is a class that implements a list of interfaces specified at runtime such that a method invocation through one of the interfaces on an instance of the class will be encoded and dispatched to another object through a uniform interface. Thus, a dynamic proxy class can be used to create a type-safe proxy object for a list of interfaces without requiring pre-generation of the proxy class, such as with compile-time tools. Method invocations on an instance of a dynamic proxy class are dispatched to a single method in the instance's invocation handler, and they are encoded with a java.lang.reflect.Method object identifying the method that was invoked and an array of type Object containing the arguments.

Standard proxy pattern https://en.wikipedia.org/wiki/Proxy_pattern

A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes. In the proxy extra functionality can be provided, for example caching when operations on the real object are resource intensive, or checking preconditions before operations on the real object are invoked. For the client, usage of a proxy object is similar to using the real object, because both implement the same interface.


原文:https://stackoverflow.com/questions/35279850
更新时间:2023-02-28 16:02

相关问答

更多
  • 这听起来像您在mobile-server地址部署了不同版本的应用程序。 本地代码以开发模式运行。 您的AWS可能处于生产模式(可能包含语法错误)。 当您运行您的应用程序时,它会看到代码不同并使用热代码重新加载来获取新/旧(不同)版本 - 因此页面刷新/闪存。 要解决此问题,您需要在代码中找到语法错误。 最好查看ADB记录器或运行meteor run --verbose android-device .... 这将提供更多信息,例如Uncaught exception: cannot read .. of n ...
  • 让我回答我的问题。 这对我来说可以。 通过构建APK meteor build ~/build-output-directory \ --server=your-desired-app-hostname.meteor.com 现在你可以通过签名你的应用程序 keytool -genkey -alias your-app-name -keyalg RSA \ -keysize 2048 -validity 10000 cd ~/build-output-directory/android/ ...
  • 你必须安装所有包,而不仅仅是fibers 。 你建立目录里面: cd programs\server npm install You'll have to install all packages, not just fibers. Inside you build directory: cd programs\server npm install
  • 对于unix,它只是: ROOT_URL=http://meteor.trivia.com:3000 meteor (开头没有“设置”) 如果使用Windows: set ROOT_URL=http://meteor.trivia.com:3000 (最后没有“流星”) 然后,在一个单独的命令中: meteor for unix, it's just: ROOT_URL=http://meteor.trivia.com:3000 meteor (no "set" at the beginning) if u ...
  • --server : 应指向您的Meteor服务器的位置(以便您的移动应用程序知道连接到基于Meteor的后端的位置)。 例如,如果您已将Meteor后端部署到Galaxy,并且已在https://yourprodurl.com ,那么您的--server设置将如下所示: --server=https://yourprodurl.com:443 --server : should point to the location of your Meteor ...
  • 您需要使用环境变量 export ROOT_URL=myserverprod.com:8080 You need to do it with an environment variable export ROOT_URL=myserverprod.com:8080
  • 我认为,您必须将模块安装/复制到projectdir/.meteor/local/build/server/node_modules ,这是指向/usr/local/meteor/lib/node_modules 。 我尝试使用node.js模块tracer并且它工作正常。 每次更新流星安装时,都必须将文件复制到此目录中。 I think, you have to install/copy your module into projectdir/.meteor/local/build/server/node ...
  • 只需使用index方法作为要呈现的特定视图的公共代理。 def index if user? logged_in else logged_out end end private def logged_in # stuff render :action => "logged_in" end def logged_out # stuff render :action => "logged_out" end Just use your index met ...
  • 当您运行容器时,它会创建自己的网络,该网络与主机网络隔离。 因此,当您使用“mongodb://127.0.0.1:27017 / meteor连接到Mongo时,它会在容器内搜索MongoDB。 而不是使用127.0.0.1使用主机IP地址或主机名。 或者,如果您的MongoDB从容器运行,则创建一个链接并使用该链接启动meteor容器。 希望这可以帮助 When you are running a container it creates its own network which is isolate ...
  • 可以在此处找到Meteor.absoluteUrl的实现。 如您所见,如果secure为true 且 ROOT_URL使用http协议, ROOT_URL使用https修改ROOT_URL ( options.rootUrl )。 如果您仍然使用https托管您的网站,我建议您将其包含在ROOT_URL ,例如https://app.example.org 。 这就是我们的工作,它运作良好。 改变环境变量而不是修改代码似乎更容易。 请注意,如果您不想指定协议,则应设置ROOT_URL如app.example ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。