靜態代理程式碼示例

zmHelloWorld發表於2020-11-23
public class StaticProxy {
    public static void main(String[] args) {
        Marry marryCampany = new MarryCampany(new You("小猴子"));
    marryCampany.HappyMarry();
    }
}


interface Marry{
    void HappyMarry();
}

class You implements Marry{

    private String name;

    public You(String name) {
        this.name = name;
    }
    @Override
    public void HappyMarry() {
        System.out.println(name+"結婚了,哈哈哈哈哈!!");
    }
}

class MarryCampany implements Marry{
    private You you;
    void before(){
        System.out.println("結婚前準備");
    }
    void ago(){
        System.out.println("結婚後");
    }
    @Override

    public void HappyMarry() {
        before();
        you.HappyMarry();
        ago();

    }

    public MarryCampany(You you) {
        this.you = you;
    }
}

相關文章