Proxy mode:
Using an environment that cannot directly use object A (a delegate object), you can use object B (the proxy object) to call object A that has reached the effect of calling object a directly, and becomes the proxy mode.
Where a is the delegate object and B is the proxy object.
Advantages and disadvantages of static proxies:
Advantages :
1, the code, you can clearly understand the entrusted Thunder and proxy class.
2, in the compilation period to join, in advance to appoint a good delegate class, proxy class, high efficiency.
Disadvantages :
1, static agent is troublesome, need a lot of proxy class, not easy code maintenance, etc.
When we have more than one target object need to proxy, I need to set up a number of proxy classes, change the original code, changed more is likely to be a problem, it must be re-tested.
2, duplicate code will appear in every corner, the code is too redundant .
3, in the compilation period, the system flexibility is poor, not easy to modify the flexibility
The pseudo code is as follows:
/** Delegate class */
Class a{
public void Method1 () {
System.out.println ("from A method");
};
}
/** proxy class */
Class b{
A;
Public B (a a) {
THIS.A = A;
}
void Method1 () {
if (null! = a) {
A.method1 ();
}
};
}
/**********/
Call procedure
Main () {
b b = new B (new A ());
B.method1 ();
}
/**************************************************** If have mistake, forget elegance, thanks! *************************************************************/
Java design mode-proxy mode-static proxy