Proxy mode of design mode (two-structure type)

Source: Internet
Author: User

1. What is proxy mode?

Provides a proxy for other objects and controls access to the object. (Provide asurrogate or Placeholderforanother object Tocontrol access to it. One reason for access control over an object is to create and initialize it only if we really need it. It provides a substitute (placeholder) for an object, making it more efficient to encode between the client object and the Subject object. Proxies can provide deferred instantiation (lazy instantiation), control access, and so on, including only passing in calls. A proxy that handles purely local resources is sometimes referred to as a virtual agent. Proxies for remote services are often referred to as remote agents. A proxy that forces access to control is called a protection agent.

Disadvantages of the proxy mode:
Because proxy objects are added between the client and the real topic, some types of proxy patterns can cause requests to be processed more slowly.
Implementing the proxy mode requires additional work, and some proxy patterns are very complex to implement.

2. Proxy mode application scenario?

intermediary rental, proxy server and so on.

3. Proxy mode use example.

Simon Qing and Pan Jinlian adultery, is through the king as an agent, to achieve, in addition if he and Chia can also have an affair, can also be by Wang Po as agent. The specific class diagram is as follows:

The core code is described as:

/*** @FileName icoquettishwoman.java* @Package com.ali.pattern.proxy* @Description todo[what the file to do]* @Author Ali Blog:Http://www.cnblogs.com/accipiter* @Date January 18, 2016 afternoon 11:34:25* @Version V1.0.1*/ PackageCom.ali.pattern.proxy;/*** @ClassName Icoquettishwoman * @Description TODO * @Date pm 11:34:25*/ Public InterfaceIcoquettishwoman { Public voidMakeeyes ();  Public voidmakelove ();}

proxy class Proxywangpo

/*** @FileName proxywangpo.java* @Package com.ali.pattern.proxy.impl* @Description todo[what the file to do]* @Author Ali Blog:Http://www.cnblogs.com/accipiter* @Date January 19, 2016 morning 12:15:32* @Version V1.0.1*/ PackageCom.ali.pattern.proxy.impl;ImportCom.ali.pattern.proxy.ICoquettishWoman;/*** @ClassName Proxywangpo * @Description TODO * @Date morning 12:15:32*/ Public classProxywangpoImplementsicoquettishwoman{PrivateIcoquettishwoman icoquettishwoman=NULL;  PublicProxywangpo (Icoquettishwoman icoquettishwoman) { This. icoquettishwoman=Icoquettishwoman; } @Override Public voidMakeeyes () { This. Icoquettishwoman.makeeyes (); } @Override Public voidMakelove () { This. Icoquettishwoman.makeeyes (); }    }

=================== Ornate Split Line =================================

Other code, want to be able to contact:

Proxy mode of design mode (two-structure type)

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.