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

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

问题描述

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



它们如何与字节码生成和反射相关?



任何推荐阅读?

解决方案

我强烈推荐这个资源



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

与静态代理相反,动态代理生成在运行时需要Java反射的字节码。使用动态,您不需要代理代理类,这可以带来更多便利。


What is a use case for using a dynamic proxy?

How do they relate to bytecode generation and reflection?

Any recommended reading?

解决方案

I highly recommend this resource.

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).

In contrast with static proxy, the dynamic proxy generates bytecode which requires Java reflection at runtime. With dynamic you need not crate the proxy class, which can lead to more convenience.

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

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