多线程静态代理_
来源: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("结婚后,收尾款!!!");
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步