静态代理模式
静态代理模式
相关视频https://www.kuangstudy.com/course/play/1317506465254887425
直接上代码
package com.example.multi_thread;
public class StaticProxy {
public static void main(String[] args) {
new WeddingCompany(new You()).happyWedding();// new Thread(()->System.out.println("aaa")).start() 对照理解静态代理模式
}
}
interface Marry {
void happyWedding();
}
class You implements Marry {
@Override
public void happyWedding() {
System.out.println("结婚啦,超开心");
}
}
class WeddingCompany implements Marry {
private You target;
public WeddingCompany(You target) {
this.target = target;
}
@Override
public void happyWedding() {
before();
target.happyWedding();
after();
}
private void after() {
System.out.println("收尾款");
}
private void before() {
System.out.println("布置婚礼现场");
}
}
布置婚礼现场
结婚啦,超开心
收尾款