什么是动态代理类,我为什么要使用一个? [英] What are Dynamic Proxy classes and why would I use one?

查看:22
本文介绍了什么是动态代理类,我为什么要使用一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用动态代理的用例是什么?

What is a use case for using a dynamic proxy?

它们与字节码生成和反射有何关系?

How do they relate to bytecode generation and reflection?

有什么推荐的读物吗?

推荐答案

我强烈推荐这个 资源.

首先,您必须了解代理模式的用例.请记住,代理的主要目的是控制对目标对象,而不是增强功能目标对象.访问控制包括同步、认证、远程访问(RPC)、延迟实例化(Hibernate、Mybatis)、AOP(事务).

First of all, you must understand what the proxy pattern use case. Remember that the main intent of a proxy is to control access to the target object, rather than to enhance the functionality of the target object. The access control includes synchronization, authentication, remote access (RPC), lazy instantiation (Hibernate, Mybatis), AOP (transaction).

与静态代理相比,动态代理生成的字节码需要在运行时进行 Java 反射.使用动态方法,您无需创建代理类,这会带来更多便利.

In contrast with static proxy, the dynamic proxy generates bytecode which requires Java reflection at runtime. With the dynamic approach you don't need to create the proxy class, which can lead to more convenience.

这篇关于什么是动态代理类,我为什么要使用一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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