public static void Main (string[] args) {
TODO auto-generated Method Stub
Proxysubject a = new Proxysubject ();
A.request ();
}
}
Interface Subject//proxy request
{
Abstract public void request ();
}
Class Realsubject implements subject{//vendor request is proxied to implement Proxy request method
public void Request ()
{
System.out.println ("I am a wine manufacturer, welcome to taste the purchase");
}
}
Class Proxysubject implements Subject//agent agent to implement Proxy request method
{
Private Realsubject Realsubject; Crucially, the reason for this declaration is that the realsubject is declared as a private variable, and there is no space for the variable at this time.
public void Request ()
{
if (realsubject==null)
Realsubject = new Realsubject ();
Realsubject.request ();
}
}
Operation Result:
I am a wine maker, welcome to taste the purchase
Java Interface-----Agent mode (proxy)