Java design pattern-proxy mode

What is a dynamic proxy is the process of dynamically generating the class file of the proxy class according to the proxy interface during the running of the program , and loading it.

So what do we want to do before generating the proxy class? That is, who will act as an agent? What needs to be done?

Take renting a house as an example. You can ask someone in the agency to help you find a house. Then that person in the agency is your agent. You don’t need to do what you want to do. Let the agent do it for you. No one else does it. Know who the agent is helping to find a house. This is the agent.

Renters need to find an intermediary, let the intermediary help you find a house, (the renter is abstracted into an interface, the person here does not refer to which one, but refers to all the people who want to rent a house ), you are the realization class , The person in the intermediary is the agent class . Finding a house is what you want to entrust the intermediary to do (others may want to sell the house), so the agent is generally the interface rather than the implementation class. Just talk to the intermediary if you want to do it. (If you want to call the method specifically, pass the corresponding implementation class to the calling processor), and the intermediary will do things according to your instructions (corresponding to the calling processor to call the method)

Related source code analysis

https://blog.csdn.net/CarryBest/article/details/112857330

 

Guess you like

Origin blog.csdn.net/CarryBest/article/details/112858014