当前位置:网站首页>Implementation steps of dynamic proxy
Implementation steps of dynamic proxy
2022-06-30 04:16:00 【If you have a guitar】
Write it at the front : Implement an agent , Whether static or dynamic , Generally, you need to create three classes and an interface : The inherited interfaces ( Provides all the methods needed to implement the class ), Delegation class ( Is the implementation class , It can be more than one ), proxy class ( All tasks of the implementation class are entrusted to the proxy class ), client ( Start the program , discharge main Where the function is )
Implementation steps of dynamic agent :
- new An implementation class object ;
- Get the proxy object that implements the class object :
2.1 call Proxy.newProxyInstance To get a dynamic proxy object , It takes three parameters , The meanings of the three parameters are respectively :
① One ClassLoader object , Defined by which ClassLoader Object to load the generated proxy object
② One Interface An array of objects , What is the set of interfaces that I'm going to provide to the object that I need to proxy , If I provide a set of interfaces to it , The proxy object then claims to implement the interface ( polymorphic ), So I can call methods in this set of interfaces
③ One InvocationHandler Implementation class object of , Represents when my dynamic proxy object is calling a method , Which one does it relate to
InvocationHandler On the implementation class object of
3. Get the class object of the proxy object ( Here we can print the class name of the class object of the proxy class )
4. Get all the methods of the proxy class ( Through violent reflection getDeclaredMethods() get )( Traverse all the obtained methods , Output all method names )
5. The method of implementing class is called by proxy object ( And the assignment ), Trigger our key steps :InvocationHandler In the implementation class of the interface invoked() Method , To execute the method that implements the class (sout Output the result )( This step is called non intrusive coding rules )
5.1 call InvocationHandler The interface steps are as follows :
After triggering the method that implements the class , The first thing you need to do is InvocationHandler Three parameters are passed in the interface , Namely
① proxy: - Refers to the real object that we are representing
② method: - It refers to a method that we want to call on a real object Method object ()
③ args: - Refers to the parameters that are accepted when a method is called on a real object
After that, the interface specific invoked() Method , Pass in two parameters , They are the real implementation class object and the parameters passed in args, Finally, return the method .
边栏推荐
- JS generator
- 基于海康EhomeDemo工具排查公网部署出现的视频播放异常问题
- matplotlib. pyplot. Hist parameter introduction
- 第十二天 进阶编程技术
- 2021-07-14
- lego_ Reading and summary of loam code
- El upload upload file (manual upload, automatic upload, upload progress)
- Solve the problem of Navicat connecting to the database
- If you encounter problems when using spark for the first time, please ask for help
- Quick sort & merge sort
猜你喜欢

How to analyze and solve the problem of easycvr kernel port error through process startup?

Thingsboard tutorial (II and III): calculating the temperature difference between two devices in a regular chain

Day 12 advanced programming techniques

Day 11 script and game AI

Basic knowledge of redis

在大厂外包呆了三年,颠覆了我的认知!

Sql语句遇到的错误,求解

FortiGate firewall configuration log uploading regularly

Interpretation score of bilstm-crf in NER_ sentence

第九天 脚本與資源管理
随机推荐
(04). Net Maui actual MVVM
第九天 脚本與資源管理
第十天 数据的保存与加载
Unity when entering a string in the editor, escape the input of characters
Unity échappe à l'entrée de caractères lors de l'entrée de chaînes dans l'éditeur
Cloud native -- websocket of Web real-time communication technology
Thingsboard tutorial (II and III): calculating the temperature difference between two devices in a regular chain
Pig-Latin (UVA492)
dotnet-exec 0.5.0 released
FortiGate firewall configuration log uploading regularly
mysql更新数组形式的json串
Project safety and quality
About manipulator on Intelligent Vision Group
Concatenation of Languages(UVA10887)
lego_loam 代码阅读与总结
El upload upload file (manual upload, automatic upload, upload progress)
RPC correction based on arcpy API
Jour 9 Gestion des scripts et des ressources
Thinkphp5 implements import function
Myrpc version 6