java中 静态代理模式

编写代码

package com.xiang.lesson07;

public class StacticProxy {
    public static void main(String[] args) {
        Wedding wedding = new Wedding();
        wedding.Wedding(new You());
        wedding.HappyMarry();
    }
}

interface Marry {
    void HappyMarry();
}

//真实角色
class You implements Marry {
    @Override
    public void HappyMarry() {
        System.out.println("marry...........");
    }
}

//代理角色
class Wedding implements Marry {
    private Marry target;

    public Wedding(){

    }


    public void Wedding(Marry target) {
        this.target = target;
    }

    @Override
    public void HappyMarry() {
        before();
        this.target.HappyMarry();
        after();
    }

    private void before() {
        System.out.println("before...........");
    }

    private void after() {
        System.out.println("after..............");
    }
}

运行结果

java中 静态代理模式

java中 静态代理模式

上一篇:Win10微软输入法不见了


下一篇:HreoWinGauge2.0组件集应用示例----数据处理