JAVA design mode proxy mode

Source: Internet
Author: User

Use

Agent mode (proxy)

Provides a proxy for other objects to control access to this object.

structure

diagram-proxy mode structure diagram

Subject : Defines the public interface of Realsubject and proxy, so that proxies can be used wherever realsubject is used.

AbstractclassSubject {
Public AbstractvoidRequest ();
}


Realsubject : Defines the real entity represented by the Proxy.

classRealsubjectextendsSubject {
@Override
PublicvoidRequest () {
SYSTEM.OUT.PRINTLN ("real request");
}
}

Proxy: Saving a reference allows the agent to access the entity and provides an interface that is the same as the Subject interface, so that the proxy can be used instead of the entity.

classProxyextendsSubject {
PrivateRealsubject Real;

@Override
PublicvoidRequest () {
if(NULL= = Real) {
Real =NewRealsubject ();
}
Real. Request ();
}
}

Application Scenarios

1. Remote Agent

Provides a localized representation for a remote object in a different address space.

2. Virtual Agent

Create expensive objects as needed. It is the real object that takes a long time to store the instantiation.

3. Security Agent

Used to control the access rights of real objects.

4. Smart Guide

is when a real object is called, the agent handles something else.

Points

The proxy mode describes an indirect level of access to an object.

A remote agent can hide the details of an object in different address spaces.

A virtual agent can optimize the cost of creating objects as needed.

Both security agents and smart guides allow access to objects while processing other transactions.

JAVA design mode proxy mode

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.