当前位置:网站首页>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 .
边栏推荐
- Day 9 script and resource management
- Redis cache avalanche, breakdown and penetration
- 工程安全和工程质量
- Es2016 key summary
- JS proxy
- Blue Bridge Cup: magic cube rotation [Vocational group]
- 管道实现进程间通信之命名管道
- Do280 private warehouse persistent storage and chapter experiment
- El upload Upload file (Manual upload, Automatic upload, upload progress)
- JS file block to Base64 text
猜你喜欢

Jour 9 Gestion des scripts et des ressources

【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码

Geometric objects in shapely

DBT product initial experience

el-upload上传文件(手动上传,自动上传,上传进度)

The school training needs to make a registration page. It needs to open the database and save the contents entered on the registration page into the database

lego_ Reading and summary of loam code

Explain the underlying principles of JVM garbage collection in simple terms

Slam mapping, automatic navigation and obstacle avoidance based on ROS (bingda robot)

第十天 数据的保存与加载
随机推荐
Idea grey screen problem
JS import and export
7-3 single source shortest circuit for strange play upgrade
MySQL DDL change
Green new power and "zero" burden of computing power -- JASMINER X4 series is popular
mysql更新数组形式的json串
Myrpc version 3
After the win10 system uses the browser to download, the content is moved or deleted without reason
Pytorch Profiler+ Tensorboard + VS Code
Collinearity problem
Graduation project EMS office management system (b/s structure) +j2ee+sqlserver8.0
[Thesis reading | deep reading] role2vec:role based graph embeddings
The jupyter notebook kernel hangs up frequently and needs to be restarted
Unity 在编辑器中输入字符串时,转义字符的输入
Knowledge - how to build rapport in sales with 3 simple skills
《机器人SLAM导航核心技术与实战》第1季:第0章_SLAM发展综述
errno和perror
2021-07-14
Redis cache avalanche, breakdown and penetration
【WEBRTC】ADM: rtc_include_internal_audio_device 触发 RTC_DCHECK(adm) 断言