编程知识 cdmana.com

Design pattern 2 -- static agent

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...");
    }
}
// delegable role 
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(" Arrangement ");
    }
    private void after(){
        System.out.println(" clean ");
    }
}

版权声明
本文为[8Years]所创,转载请带上原文链接,感谢

Scroll to Top