多线程静态代理_
来源:https://www.bilibili.com/video/BV1V4411p7EF?p=9
静态代理
以结婚为例子
package com.hao.Demo01;
public class StaticProxy {
public static void main(String[] args) {
new Thread( ()-> System.out.println("i love you.")).start();
new WeddingCompany(new You()).HappyMarry();
}
}
interface Marry{
void HappyMarry();
}
//真实角色,你结婚
class You implements Marry{
@Override
public void HappyMarry() {
System.out.println("你要结婚了,HappyMarry");
}
}
//代理角色,帮你结婚
class WeddingCompany implements Marry{
private Marry target;
public WeddingCompany(Marry target) {
this.target = target;
}
@Override
public void HappyMarry() {
before();
this.target.HappyMarry();
after();
}
private void before() {
System.out.println("结婚前,布置现场");
}
private void after() {
System.out.println("结婚后,收尾款!!!");
}
}