package com.Thread;
/**
* 动态代理
* 实现共同的接口
* 代理类持有真实类的引用
*/
public class staticProxy {
public static void main(String[] args) {
//创建真实角色
You you = new You();
//创建代理 + 真实角色引用
WeddingCompany wc = new WeddingCompany(you);
//执行
wc.marry();
}
}
//接口
interface Marry {
public abstract void marry();
}
//真实类
class You implements Marry {
public You() {
}
@Override
public void marry() {
System. out.println("我要娶你!" );
}
}
//代理类
class WeddingCompany implements Marry {
private You you ;
public WeddingCompany(You you) {
this.you = you;
}
public void before() {
System. out.println("布置中。。。。" );
}
public void affter() {
System. out.println("结束了。。。" );
}
@Override
public void marry() {
before();
you.marry();
affter();
}
}