1. Proxy mode
Provides a proxy for other objects to control access to this object.
- Remote Proxy: Provides a report representative for an object in a different address space. This can hide the fact that an object is in a different address space.
- Virtual proxy: Creates expensive objects on demand. It's the real object that takes a long time to store the instantiation.
- Security Agent: The permission used to control the access of real objects.
- Smart proxy: The agent handles other things when a real object is called.
2. Example
namespaceProxy Mode {classProgram {Static voidMain (string[] args) {girlmm mm=Newgirlmm (); Mm. Name="Summer Wallpaper"; Proxy proxy=NewProxy (mm); Proxy. Givedolls (); Proxy. Giveflowers (); Proxy. Givechocolate (); Console.ReadLine (); } } /// <summary> ///operation interface performed by the proxy object/// </summary> InterfaceIgivegift {voidGivedolls (); voidgiveflowers (); voidgivechocolate (); } /// <summary> ///class that the agent wants the agent to perform operations on/// </summary> classGIRLMM {Private stringname; Public stringName {Get{returnname;} Set{name =value;} } } /// <summary> ///represented by/// </summary> classPursuit:igivegift {girlmm mm; PublicPursuit (girlmm mm) { This. mm =mm; } Public voidGivedolls () {Console.WriteLine (mm). Name+"give you a doll ."); } Public voidGiveflowers () {Console.WriteLine (mm). Name+"Send you flowers"); } Public voidGivechocolate () {Console.WriteLine (mm). Name+"give you the chocolates ."); } } classproxy:igivegift {Pursuit gg; PublicProxy (girlmm mm) {GG=NewPursuit (mm); } Public voidgivedolls () {Gg. Givedolls (); } Public voidgiveflowers () {Gg. Giveflowers (); } Public voidgivechocolate () {Gg. Givechocolate (); } }}
(C #) proxy mode