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)