Obviously. We are currently living in the world. They are all right. They are willing to help us to complete my own work. I am willing to act as a middle layer. In this level. Proxy agent is dominant He will handle things that look very much about it. After all, our goal is to develop the overall policy. Subject details can be delivered to the agent. In fact, many cases. We all used the agent. For example, we are. Using WebService in NET is already using Proxy. Through this proxy and actual remote objects. The actual remote object is passed through WebService. This is the so-called remote agent. Of course there are many agents. Such as You have to write something that is permission. So customers can't deal with this thing. So, by the agent to manage privileges and customers are dealing with the actual object. This is the so-called protection agent. Actually because it is a proxy Therefore, customers do not need to manage the release and creation of the actual object. This is also done through the agent. Hypothesis. I am a knight. I am going to be met by a beautiful princess. I am honored. Unfortunately, the princess is only in this battle. People who have war meet. So you must show my medal. You can meet with the princess. OK let us simulate this scene .NameSpace proxymeeting {using system;
INTFACE IMETING {void kmeeting ();
class Knight: IMeeting {private bool exploit; private string KName; public Knight (string KN) {merit from the database queries whether this.exploit = IsExploit;} public void Request () {if (exploit) Console.WriteLine ( "successfully met "); Else Console.writeline (" Unable to meet ");}}
Class Proxy: Imeeting {Private Knight Km; Public Void Request () {IF (km == NULL) KM = New Knight (this.kname); km.Request ();}} // Really meet public Class Infanta {public static int main (String [] args) {// The princess is not directly dealing with the Knight. But through agent proxy p = new proxy (); p.kname = "yarshray; p.Request (); return 0;}}}
It can be seen here. The princess did not deal with the knight, but passed the agent. Even if the Cavalier's creation work is done by the agent. And the agent also manages whether the knight is built in this battle. Come decide whether to meet the princess Everything is the same as we expected?