即日起在codingBlog上分享您的技术经验即可获得积分,积分可兑换现金哦。

notes is better than memory装饰者模式

编程语言 Damionew 9℃ 0评论

接口

public interface Worker {
 void doSomework();
}

实现接口

public class Plumber implements Worker{
 public void doSomework(){
  System.out.println("修水管");
 }

}
public class Carpenter implements Worker{
 public void doSomework()
 {
  System.out.println("修门窗");
 }
}
public class Carpenter implements Worker{
 public void doSomework()
 {
  System.out.println("修门窗");
 }
}

实现测试类

public class Test {
 public static void main(String args[]){
  Plumber plumber=new Plumber();
  AWorker aworker=new AWorker(plumber);
  aworker.doSomework();
  
  Carpenter carpenter=new Carpenter();
  AWorker aworker2=new AWorker(carpenter);
  aworker2.doSomework();
 }
}











转载请注明:CodingBlog » notes is better than memory装饰者模式

喜欢 (0)or分享 (0)
发表我的评论
取消评论

*

表情