The proxy mode of Java design pattern

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.