Proxy mode: Provides a proxy for other objects to control access to this object.
Simple example:
1 Public InterfaceSubject2 {3 Public voidoperate ();4 }5 6 Public classRealsubjectImplementsSubject7 {8 Public voidoperate ()9 {TenSystem.out.println ("Real operation.")); One } A } - - Public classProxyImplementsSubject the { - PrivateSubject Subject; - - Proxy (Subject Subject) + { - This. Subject =subject; + } A at Public voidoperate () - { - Dobefore (); - subject.operate (); - Doafter (); - } in - Public voidDobefore () to { +System.out.println ("Before ..."); - } the * Public voidDoafter () $ {Panax NotoginsengSystem.out.println ("After ..."); - } the } + A Public classTest the { + Public Static voidMain (string[] args) - { $Subject Subject =NewRealsubject (); $Subject proxy =NewProxy (subject); - proxy.operate (); - } the}
Application form of proxy mode:
(1) Remote proxy-You can hide the fact that an object exists in a different address space. Also allows the client to access objects on the remote machine, the remote machine may have better computational performance and processing speed, and can quickly respond to and process client requests.
(2) Virtual proxy – allows objects with large memory overhead to be created when needed. It is only created when we really need this object.
(3) Copy-on-write agent (Copy-on-write proxy) – Used to control the replication of objects by delaying the copying of objects until the customer really needs them. is a variant of the virtual agent.
(4) Protection agent (Protection (access) proxy) – provides different levels of access to target objects for different customers.
(5) Cache proxy – provides temporary storage for the result of a costly operation that allows multiple customers to share results to reduce compute or network latency.
(6) Firewall proxy (Firewall proxy) – Control access to network resources and protect topics from malicious customers.
(7) Synchronous agent (synchronization proxy) – Provides secure access to topics in multi-threaded situations.
(8) Smart Reference Agent (Smart Reference proxy)-When an object is referenced, provides some extra action, such as recording the number of times this object is called.
(9) Complex hidden agent (complexity hiding proxy) – Used to hide the complexity of a complex set of classes and access control. Sometimes also known as the appearance of agents, it is not difficult to understand. Complex hidden proxies and appearance modes are not the same because the agent Controls access, while the façade mode only provides another set of interfaces.
Reference: http://blog.csdn.net/jackiehff/article/details/8621517
The proxy mode of Java design pattern