This is the fifth day of my participation in Gwen Challenge
This article has participated in the weekend study program, click to see more details
You see what I want you to see, and you hear what I want you to hear! Confessions of the agency model
No less foreplay
Foreplay 1: in life, we often see such a phenomenon: some parents hold the “hope children become a dragon, hope women become phoenix” mentality, all the children’s affairs (food, clothing, housing, eating and drinking) all wrapped up, can be said to be in every detail.
Foreplay TWO: in ancient times, men and women could not meet each other before they got married, and a lot of information between them was transmitted to each other through the matchmaker, whether ugly or beautiful, tall or short, and not by the matchmaker’s mouth.
Did you get any sense from the foreplay?
The child is ruined…
Evil feudal society…
Ahem!!!!! Please note: we are talking about the agency model of scientific knowledge today, not social issues!
Get to the point
I’m not doing this foreplay to impress, I’m doing it for a reason!
Let’s first look at the definition of the proxy * schema:
For some reason you need to provide a proxy for an object to control access to that object. In this case, the access object is not suitable or cannot directly reference the target object, and the proxy object acts as an intermediary between the access object and the target object.
If we take the two examples at the beginning of the article as the agency model, then combining the definition, we can take the parents and matchmaker in the figure above as the “agency object”.
About the Proxy Model
advantages
- Proxy mode plays an intermediary role and protects the target object between the client and the target object.
- Proxy objects extend the functionality of target objects.
- The proxy mode can separate the client from the target object, reduce the coupling degree of the system to a certain extent, and increase the scalability of the program.
disadvantages
- The proxy pattern increases the number of classes in the system design.
- Adding a proxy object between the client and the target object slows request processing.
- Increased system complexity.
classification
- A static proxy class is created by a programmer, or a specific tool automatically generates source code and compiles it. The.class file of the proxy class already exists before the program runs.
- Dynamic proxies are created dynamically using reflection while the program is running
composition
- Abstract Subject class: Business methods that declare real topics and proxy object implementations through interfaces or abstract classes.
- Real Subject class: Implements the concrete business in an abstract topic, is the Real object represented by the proxy object, and is the object ultimately referenced.
- Proxy class: Provides the same interface as a real topic, with internal references to real topics that can access, control, or extend the functionality of real topics.
At the end
Today we mainly have a relatively simple understanding of the agency model, and we will expand on it later. Thank you for reading!
Learn interesting knowledge, meet interesting friends, shape interesting soul!
Everybody is good! I am the author of programming Samadhi, yi Wang, my public account is “programming Samadhi”, welcome to pay attention to, I hope you can give me more advice!
Pay equal attention to knowledge and skills, both internal force and external power repair!