Java多线程(静态代理)
作者:互联网
//静态代理模式总结; //真实对象和代理对象要实现同一个接口 //代理对象要代理真实角色 //好处: //代理对象可以做很多真实对象做不了的事情 //真实对象专注做自己的事情 public class StacticProxy { public static void main(String[] args) { weddingCompany weddingCompany=new weddingCompany(new You()); weddingCompany.HappyMarry(); } } interface Marry{ void HappyMarry(); } //真实角色 class You implements Marry{ @Override public void HappyMarry() { System.out.println("xxx要结婚"); } } //代理角色 class weddingCompany implements Marry{ private Marry target; public weddingCompany(Marry target){ this.target=target; } public void HappyMarry(){ before(); this.target.HappyMarry();//这就是真实对象 after(); } private void before(){ System.out.println("结婚之前,布置现场"); } private void after(){ System.out.println("结婚之后,交尾款"); } }
标签:Java,target,静态,void,weddingCompany,Marry,HappyMarry,多线程,public 来源: https://www.cnblogs.com/ooo926/p/15140690.html