Second, the static proxy mode

https://jingyan.baidu.com/article/da1091fbecee3c427849d6f0.html

1  Package com.sxt.thread;
 2  / ** 
. 3  * static agent
 4  * public interface:
 5  * 1, the real role of
 6  * 2, the agent role
 . 7  * 
 . 8  * . 9  *
 10   * / 
. 11  public  class StaticProxy {
 12 is      public  static  void main (String [] args) {
 13 is          new new WeddingCompany ( new new by You ()) happyMarry ();.
 14          
15          // new new the thread (thread object) .start (); 
16      }
 . 17  }
 18 is  interface{Marry
 19      void happyMarry ();
 20  }
 21  // real role 
22  class by You the implements Marry {
 23  
24-      @Override
 25      public  void happyMarry () {
 26          System.out.println ( "you and Ben Chang-e last months ... . " );
 27      }
 28      
29  }
 30  // agent role 
31 is  class WeddingCompany the implements Marry {
 32      // true character 
33 is      Private Marry target;
 34 is      public WeddingCompany(Marry target) {
35             this.target = target;
36     }
37     @Override
38     public void happyMarry() {
39         ready();
40         this.target.happyMarry();
41         after();
42     }
43     
44     private void ready() {
45         System.out.println("布置猪窝。。。。");
46     }
47     private void after() {
48         System.out.println("闹玉兔。。。。");
49     }
50 }

 

Guess you like

Origin www.cnblogs.com/qiaoxin11/p/12606853.html