java:装饰模式,节点流和处理流

java:装饰模式,节点流和处理流

接口:

interface Worker
{
    public void dowork();
}

清洁工:被装饰者,节点流

class Clean implements Worker
{
    public void dowork(){
        System.out.println("搞清洁");
    }
}

A公司:装饰者,处理流

java:装饰模式,节点流和处理流
class Aworker implements Worker
{
    private Worker worker;    //传进来的对象是woker的实现类
    public Aworker(Worker worker){
        this.worker = worker;
    }
    public void dowork(){
        System.out.println("A公司");
        worker.dowork();
    }
}
java:装饰模式,节点流和处理流

实例化:

java:装饰模式,节点流和处理流
class Test
{
    public static void main(String args[]){
        Clean clean = new Clean();
        Aworker worker1 = new Aworker(clean);
        worker1.dowork();
    }
}
java:装饰模式,节点流和处理流

 

java:装饰模式,节点流和处理流,布布扣,bubuko.com

java:装饰模式,节点流和处理流

上一篇:charles中下载web证书


下一篇:[leetCode][001] Maximum Product Subarray