编程知识 cdmana.com

设计模式2—— 静态代理

public class Test {
    
    public static void main(String[] args) {
        new maryCompany(new you()).getMary();
    }
    
}

interface Mary{
    void getMary();
}

class you implements Mary{
    @Override
    public void getMary() {
        System.out.println("mary...");
    }
}
//代理角色
class maryCompany implements Mary{
    private Mary target;

    public maryCompany(Mary target) {
        this.target = target;
    }

    @Override
    public void getMary() {
        ready();
        this.target.getMary();
        after();


    }

    private void ready(){
        System.out.println("布置");
    }
    private void after(){
        System.out.println("打扫");
    }
}

版权声明
本文为[8Years]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4583813/blog/4712878

Tags mary
Scroll to Top