java装饰模式-2016软件设计师下半年-下午真题

发布时间:2019-11-20 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了java装饰模式-2016软件设计师下半年-下午真题脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
class Invoice{     public void PRintInvoice(){         System.out.println("this is content");     } }  class Decorator extends Invoice{     protected Invoice ticket;     public Decorator (Invoice t){         ticket=t;     }     public void printInvoice(){         if(ticket!=null){             ticket.printInvoice();         }     } }  class HeaderDecorator extends Decorator{              public HeaderDecorator(Invoice t){         suPEr(t);     }     public void printInvoice(){         System.out.println("this is the header");         super.printInvoice();     }      }  class FooterDecorator extends Decorator{          public FooterDecorator(Invoice t){         super(t);     }     public void printInvoice(){                  super.printInvoice();         System.out.println("this is the footer");     }      }    public class zhuangshi {          public static void main(String[] args){         Invoice t =new Invoice();         Invoice ticket;         ticket=new FooterDecorator(new HeaderDecorator(t));         ticket.printInvoice();         System.out.println("=====================");         ticket=new FooterDecorator(new HeaderDecorator(new Decorator(null)));         ticket.printInvoice();     }  } 

结果

java装饰模式-2016软件设计师下半年-下午真题

脚本宝典总结

以上是脚本宝典为你收集整理的java装饰模式-2016软件设计师下半年-下午真题全部内容,希望文章能够帮你解决java装饰模式-2016软件设计师下半年-下午真题所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。