package com.jishu.demo01;


//代理结婚 案例
public class StaticProxy {

public static void main(String[] args) {

WeddingCompany weddingCompany = new WeddingCompany(new you());
weddingCompany.HappyMarry();
}
}

interface Marry{

void HappyMarry();
}

//真实角色
class you implements Marry{

@Override
public void HappyMarry() {
System.out.println("我想结婚");
}
}

//代理角色,帮助我结婚
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 after() {
System.out.println("结婚之前布置现场");
}

private void before() {
System.out.println("结婚之后收尾款");
}
}
posted on 2020-08-11 23:12  Maluou  阅读(140)  评论(0编辑  收藏  举报