package demo1;
public class StaticProxy {
public static void main(String[] args) {
new Thread(()-> System.out.println("我爱你")).start();
MarryCompany marryCompany = new MarryCompany(new You());
marryCompany.HappyMarry();
}
}
interface Marry {
void HappyMarry();
}
class You implements Marry{
@Override
public void HappyMarry() {
System.out.println("我结婚啦,超开心");
}
}
class MarryCompany implements Marry{
You target;//创建一个you对象
public MarryCompany(You target) {
this.target = target;
}
@Override
public void HappyMarry() {
before();
target.HappyMarry();
after();
}
private void after() {
System.out.println("结婚后,含泪缴费");
}
private void before() {
System.out.println("结婚前,准备工作");
}
}
静态代理模式,相当于创建一个或多个功能少的实现类和一个功能多的实现类,两个类实现同一个接口,将少功能类传入多功能类,在多功能类中调用自身方法和少功能方法
标签:MarryCompany,target,静态,void,代理,System,初步,HappyMarry,public From: https://www.cnblogs.com/qt0312/p/16833816.html