Java three agents-static, dynamic agent, Cglib

Reference article:

1. https://www.zhihu.com/question/20794107/answer/658139129 (Explanation of static and dynamic agents in detail)

2. About Cglib: https://zhuanlan.zhihu.com/p/70098824

 


1. The overall purpose of the agency : to expand the functions of the target object. Does not change its own function;

2. Common proxy modes : static, dynamic, Cglib proxy. The first two are suitable for the target object that implements the interface, and the latter is suitable for the target object that does not implement the interface;

3. The proxy idea of ​​the target object with interface: Based on the idea of ​​copy + extension, create a proxy class: In order to better expand on the original basis, the proxy class and the target class can realize the same interface (similar to copy, then Expand);

4. Based on different "copy" methods, it is divided into static and dynamic agents : the following are mainly used for understanding and memory, and the specific code refers to the article.

preview

  • The static is as follows:

preview

  • The dynamics are as follows:

Skip generating proxy classes and directly generate proxy objects.

 

About the bridge between the proxy object and the target object-InvocationHandler object:

 

 

 

Guess you like

Origin blog.csdn.net/Longtermevolution/article/details/108336244