1, definition: Provide a proxy for other objects to control access to this object. In some cases, an object does not fit or cannot directly reference another object, and a proxy object can act as an intermediary between the client and the target object.
2. Class diagram: The proxy object and the Proxied object have a common parent interface, and the proxy object relies on the proxy object.
3. Advantages:
- The proxy mode can separate the proxy object from the object that is actually called, and reduce the coupling degree of the system to some extent;
- The proxy mode acts as a mediator between the client and the target object, which can act as a protection target object. The proxy object can also do other things before or after the target object is called.
4. Disadvantages:
- Increase the complexity of the system;
- Adding a proxy object to the client and target object causes the request to be processed slowly;
5. Application Scenario:
- Remote proxy: Provides a local proxy for an object in a different address space, which can hide the fact that an object is in a different address space;
- Virtual Agent: It is necessary to create a very expensive object, through which to store the real object that takes a long time to instantiate;
- Security agent: Used to control the real object access permissions, generally used for objects have different access rights;
- Firewall proxy: Protect the target, do not let the malicious user close;
- Smart pointer: Refers to when the real object is called, the agent handles other things;
- Lazy loading: A classic application for deferred loading with proxy mode is the Load method in hibernate framework;
The proxy mode of Java design pattern