Proxy mode provides a proxy object for an object and controls the reference to the source object by the proxy object. An agent is an action taken by one person or institution on behalf of another person or institution. In some cases, the customer does not want or cannot directly reference an object. The proxy object can serve as an intermediary between the customer and the target object. The client cannot identify the proxy topic object and the real topic object. The proxy mode does not know the real proxy object, but only holds an interface of the proxy object. At this time, the proxy object cannot be created as the proxy object, the proxy object must have other roles created and passed in on behalf of the system.
Example:
1 interface demo {
2 Public void action ();
3}
4
5 class realdemo implements demo {
6 @ override
7 public void action (){
8 system. Out. println ("this is a real implementation class ");
9}
10}
11
12 class proxydemo implements demo {
13 private demo real;
14 public proxydemo (){
15 system. Out. println ("this is the proxy class ");
16 real = new realdemo ();
17}
18 @ override
19 public void action (){
20 system. Out. println ("Agent started ");
21 Real. Action ();
22 system. Out. println ("Agent ended ");
23}
24}
25
26 public class test {
27 public static void main (string [] ARGs ){
28 demo = new proxydemo ();
29 demo. Action ();
30}
31}