java 适配器模式-2016软件设计师上午题考试

发布时间:2019-11-19 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了java 适配器模式-2016软件设计师上午题考试脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

先点击看看题目要求:uml 类图

适配器代码实现

class Address{   public void street(){System.out.PRintln("正常街道");}   public void zip(){System.out.println("正常邮编");}   public void cITy(){System.out.println("正常地方");} }  class DutchAddress{   public void straat(){System.out.println("荷兰语街道");}   public void postcode(){System.out.println("荷兰语邮编");}   public void plaats(){System.out.println("荷兰语地方");} }  class DutchAddressAdapter extends DutchAddress{   private Address address;   public DutchAddressAdapter(Address addr){     this.address=addr;   }   public void straat(){     this.address.street();   }   public void postcode(){     this.address.zip();   }   public void plaats(){     this.address.city();   } }  public class test {   public static void main(String[] args){     Address addr=new Address();     DutchAddress addrAdapter=new DutchAddressAdapter(addr);     System.out.println("n THE DUCTH ADDRESSn");     testDutch(addrAdapter);   }   static void testDutch(DutchAddress addr){     addr.straat();     addr.postcode();     addr.plaats();   } } 

附赠一个画和画方的

class Yuan{     public void pp(String str){         System.out.println("我只能pp画圆");         System.out.println("圆打出来个 "+str);         } }  class fang{     public void ppp(String str){         System.out.println("我只能ppp画方");         System.out.println("方打出来个 "+str);         } } class fangAdapter extends Yuan{          private Fang fang;     public fangAdapter (Fang fang){         System.out.println("我能用pp画圆,也能用ppp画方");         this.fang=fang;     }     public void ppp(String str){         this.fang.ppp(str);     } }  public class RoundSquere {      public static void main(String[] args){                  Fang F1=new Fang();                  fangAdapter fy=new fangAdapter(f1);                  fy.pp("hhh");         fy.ppp("ooo");              } } 

脚本宝典总结

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

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

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