标签:style c class blog code java
接口:
interface Worker { public void dowork(); }
清洁工:被装饰者,节点流
class Clean implements Worker { public void dowork(){ System.out.println("搞清洁"); } }
A公司:装饰者,处理流
class Aworker implements Worker { private Worker worker; //传进来的对象是woker的实现类 public Aworker(Worker worker){ this.worker = worker; } public void dowork(){ System.out.println("A公司"); worker.dowork(); } }
实例化:
class Test { public static void main(String args[]){ Clean clean = new Clean(); Aworker worker1 = new Aworker(clean); worker1.dowork(); } }
java:装饰模式,节点流和处理流,布布扣,bubuko.com
标签:style c class blog code java
原文地址:http://www.cnblogs.com/tinyphp/p/3753546.html