何时使用“动态代理类”或“标准代理”模式?(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
相关问答
更多-
Meteor android构建版本(Meteor android build version)[2023-05-23]
这听起来像您在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/ ...
-
启动Meteor Build(Start Meteor Build)[2023-06-29]
你必须安装所有包,而不仅仅是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 -
meteor js更改主机名(meteor js change hostname)[2023-07-25]
对于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 ... -
Meteor.js:为生产构建iOS应用程序-server
: [2021-07-14]指向哪里?(Meteor.js: Build iOS app for production Where should –server : point?) --server: 应指向您的Meteor服务器的位置(以便您的移动应用程序知道连接到基于Meteor的后端的位置)。 例如,如果您已将Meteor后端部署到Galaxy,并且已在https://yourprodurl.com ,那么您的--server设置将如下所示: --server=https://yourprodurl.com:443 --server : should point to the location of your Meteor ... -
如何在Meteor应用程序的构建时指定生产服务器地址?(How to specify the production server address at build for a Meteor app?)[2023-12-14]
您需要使用环境变量 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 ...
-
条件root_url(索引)(Conditional root_url (index))[2023-08-06]
只需使用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的$ ROOT_URL环境变量的协议吗?(Should I include the protocol for Meteor's $ROOT_URL environment variable?)[2022-02-26]
可以在此处找到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 ...