静态代理
【小城贝尔】
一个接口上边挂,代理具体都在下。
接口必在代理中,构造传值具体风。
代理之中的操作,添油加醋具体落。
两个角色实例化,代理操作便天下。
static proxy :静态代理
public class StaticProxyDemo {
public static void main(String[] args) {
Groom groom = new Groom();
//代理
MarryCompany mc = new MarryCompany(groom);
mc.marring();
/*
before 。。。帮忙张罗
groom is marriong
after .....收钱before 。。。帮忙张罗
groom is marriong
after .....收钱before
*/
}
}
//抽象角色
interface Marry{
void marring();
}
//具体角色
class Groom implements Marry{
@Override
public void marring() {
System.out.println("groom is marriong");
}
}
// 代理角色、
class MarryCompany implements Marry{
private Marry marry;
public MarryCompany(Marry marry) {
this.marry = marry;
}
@Override
public void marring() {
System.out.println("before 。。。帮忙张罗");
marry.marring();
System.out.println("after .....收钱");
}
}