1. 这里是静态代理 实现模拟了结婚。
package com.yyf.Thread.demo1;
public class StaticProxy {
public static void main(String[] args) {
You you = new You ();
// 用线程的方式
new Thread (()-> System.out.println ("我爱你")).start ();
new WeddingCompany (you).happyMerry ();
//WeddingCompany weddingCompany = new WeddingCompany (you);
//weddingCompany.happyMerry ();
}
}
interface Merry{
void happyMerry();
}
class You implements Merry{
@Override
public void happyMerry() {
System.out.println ("我要结婚了");
}
}
class WeddingCompany implements Merry{
private Merry merry;
public WeddingCompany(Merry merry){
this.merry=merry;
}
@Override
public void happyMerry() {
before();
this.merry.happyMerry ();
after();
}
void before(){
System.out.println ("布置婚礼现场");
}
void after(){
System.out.println ("收尾款");
}
}
|