Depth analysis of proxy mode

@ (Depth analysis proxy mode)

Depth analysis of proxy mode

  1. Master proxy mode of application scenarios
  2. Understand the difference between static and dynamic proxy agent
  3. CGLib and understand the fundamental difference between the JDK Proxy
  4. Handwritten implementation-defined dynamic proxy

Content targeting

  • We know how to be a proxy mode to achieve SpringAOP when, in the end is how to achieve it?
  • Simulation own handwriting to restore some of the details

Define a proxy mode

Agent mode (Proxy Pattern) refers to provide a proxy for other objects, to control access to the object.

Proxy object mediates between the client and the target audience.

Structural design patterns belonging to

Life in proxy mode

  • Real Estate Agents
  • Express little brother
  • Scalpers

Proxy mode usage scenarios

  • Protection of the target object
  • Enhanced Audience

Static agents

  • Display declaration is a proxy object

Data source routing eg: dynamically switching the data source

defect

It does not comply with the principle of opening and closing, as long as the agent of the class needs a new agency, we need to add a new method in the proxy class

Dynamic proxy ($ Proxy0)

  1. Get the proxy class references, and get all of his interfaces (reflecting acquisition) need to implement the interface
  2. JDK Proxy class to re-generate a new class that implements the method of the proxy class for all interfaces
  3. Jav dynamically generated code to enhance logic is added to the newly generated code.
  4. Java code compiler to generate new class files
  5. Loading and re-run the new class, derived class is the new class

Proxy is a utility class used to generate a new proxy class

Why the length of the interface of this class can not be greater than 65535?

Guess you like

Origin www.cnblogs.com/mengjie1001/p/10926451.html