background : When it comes to reflection mechanism , You're sure to think of dynamic agents .

Easy to learn ,Java Agent mode and dynamic agent in

The proxy pattern can be used without modifying the proxy object , By extending the proxy class , Add and enhance some functions . It is worth noting that , The proxy class and the surrogate class should implement an interface together , Or inherit a class together .

Static proxy

Proxy classes need to write their own code as .

A dynamic proxy


  • loader Nature is a class loader
  • interfaces The interface the code is going to use as a proxy
  • h One InvocationHandler object


The interior is just one invoke() Method , It is this method that determines how to handle the method call passed by the proxy .

  • proxy Proxy object
  • method Method called by proxy object
  • args Parameters in the called method

The dynamically generated proxy class name is the package name +$Proxy+id Serial number


In the software industry ,AOP by Aspect Oriented Programming Abbreviation , Meaning for : Section oriented programming , A technique for unified maintenance of program functions through precompilation and runtime dynamic proxies .AOP yes OOP The continuation of , It is a hot topic in software development , It's also Spring An important part of the framework , Is a derivative paradigm of functional programming . utilize AOP Parts of the business logic can be isolated , Thus the degree of coupling between the parts of the business logic is reduced , Improve program reusability , At the same time improved the efficiency of development .

The main function
logging , Performance statistics , safety control , Transaction processing , Exception handling and so on .


There are two kinds of proxy: static proxy and dynamic proxy .
Static proxy , Proxy classes need to write their own code as .
A dynamic proxy , The proxy class passes through Proxy.newInstance() Method generation .
Whether it's a static proxy or a dynamic proxy , Both the agent and the agent have to implement two interfaces , Their essence is interface oriented programming .
The difference between a static proxy and a dynamic proxy is whether developers define it themselves Proxy class .
Dynamic proxy through Proxy Dynamic generation proxy class, But it also specifies a InvocationHandler Implementation class of .
The essence of the proxy pattern is to enhance the functionality of existing code .

( turn ) Easy to learn ,Java Agent mode and dynamic agent in

  1. Java Design patterns - Dynamic agent of agent model ( With source code analysis )

    Java Design patterns - Dynamic agent of agent model ( With source code analysis ) Dynamic agent concept and class diagram Static proxies were introduced in the previous article , One of the biggest differences between dynamic agents and static agents is : Dynamic proxy is to dynamically create proxy class and its objects at execution time . The static generation in the first part ...

  2. Dynamic proxy model ——JDK A dynamic proxy

    today , Let me talk about the design pattern of dynamic agent . The meaning of dynamic proxy is to generate a proxy object , To represent real objects , To control access to real objects . There are two steps to operating a dynamic proxy : One . Agent object and real object establish agent relationship . Two . Implements a proxy for a proxy object ...

  3. 【Java Basics 】java Reflection mechanism and dynamic proxy in

    One .java The reflection mechanism in java The official definition of reflection : In the running state , You can get all the properties and methods of any class , And all methods of a class can be called through any object instance of the class . This function of dynamically obtaining class information and dynamically calling methods in a class is called ja ...

  4. Java Reflection mechanism and dynamic proxy in

    One . Reflection Overview The reflex mechanism refers to Java There's a self-awareness at runtime , Be able to understand your own situation and prepare for the next step , What it means is : In the running state , For any class , You can get all the properties and methods of this class : For any object ...

  5. JAVA Agent mode and dynamic agent mode

    1. The proxy pattern The so-called agent , It's one person or agency acting on behalf of another person or agency . In some cases , A customer doesn't want or can't directly reference an object , The proxy object can act as a mediator between the client and the target object . Agent mode for a ...

  6. Java The three agent models of (Spring Dynamic proxy object )

    Java The three agent models of 1. The proxy pattern agent (Proxy) It's a design pattern , Provides additional access to the target object ; That is, access the target object through the proxy object . The advantage of this is : It can be realized on the basis of the target object , Enhance additional functional operations , Immediate expansion ...

  7. java Proxy pattern and dynamic proxy class

     1.      The proxy pattern The role of the agency model is : Provides a proxy for other objects to control access to this object . In some cases , One customer doesn't want or can't directly reference another object , The proxy object can mediate between the client and the target object ...

  8. Java Dynamic agent of agent model

    The source code of dynamic proxy class is generated by JVM Dynamically generated according to mechanisms such as reflection , So there is no bytecode file for the proxy class . The connection between the proxy role and the real role is determined when the program runs ! Java There are two kinds of dynamic agents in , One is JDK Self contained , Another kind of CGL ...

  9. The proxy pattern -jdk A dynamic proxy

    IDB package com.bjpowernode.proxy; /** * Both the proxy class and the target class must use the same interface . */ public interface IDB { int insert(); ...

Random recommendation

  1. On my understanding of C# Understanding of abstract classes and interfaces in

    C# The abstract classes in are somewhat similar to interfaces , It's easy for beginners to confuse , Today let me talk about the understanding of the two . First of all, we have to be clear about the meaning of the two , It is described as follows : If a class is not related to a specific thing , It's just an abstract concept , Just as one of its derived classes ...

  2. yii2 Access control rbac The menu menu The most detailed course

    In front of us in the blog  yii2 Build the perfect backstage and realize rbac The example of privilege control is perfectly realized in the tutorial yii2 Backstage building and rbac Access control , If you haven't realized it yet , Please look at the above and come back to this article , Because this article is based on the above to improve and supplement . ...

  3. android-tools-adb

    sudo apt-get install android-tools-adbsudo apt-get install android-tools-fastboot

  4. The 12th Zhejiang college students program design competition -May Day Holiday classification : match 2015-06-26 14:33 10 Human reading Comment on (0) Collection

    May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...

  5. 【 turn 】C# rewrite WndProc Intercept send out System message + windows Message constant value (1)

    C# rewrite WndProc Intercept send out System message + windows Message constant value (1) #region Intercept the message         /// Intercept the message   Handle XP Can not shut down the problem         protected ...

  6. java Get the black screen information and save it in list in , Intercept character execution

    ArrayList<String> list1 = new ArrayList<String>(); Process p = Runtime.getRuntime().exec ...

  7. Spring Bean Life cycle

    from : Also on Spring Bean Life cycle of Let's start with an old picture Spring in Bean The life cycle of the container . Cut in , I remember a blog post about :“Spring Of Bean Containers only manage non singletons Bean Life cycle of , Single case ...

  8. css:background-position &gt; Elf technology

    background-position : length || length background-position : position || position  Value : length  : percentage ...

  9. spark Partition number ,task number ,core Count ,worker Number of nodes ,excutor Quantity sorting

    author : Wang Jinguang Links : source : It's up to the author to own the copyright . Commercial reprint please contact the author for authorization , Non commercial reprint please indicate ...

  10. ltp-ddt git

    ltp-ddt There is a folder in the directory confrVOaeL confvp5WrA This folder is made up of ./configure --host=arm-linux-gnueabihf Command generated . Every time configu ...