【2013-12-17】设计模式学习笔记:门面模式
[历史归档]本文原发布于 cstriker1407.info 个人博客内容为历史存档仅供参考。发布时间2013-12-17 标题设计模式学习笔记门面模式分类编程 / 设计模式 / java 标签设计模式·java·门面模式设计模式学习笔记门面模式最近在看《设计模式之禅》这本书收获良多作者不愧是工作多年的大牛将各种设计模式讲解的非常透彻。这里备份下书中的【门面模式 】代码github【 https://github.com/cstriker1407/design_pattern 】门面模式比较简单而且容易使用代码重构时可以很方便的掩盖掉具体的业务实现。interfaceLetterPost{publicvoidwrite(Stringstr);publicvoidsend(Stringaddresss);}classPersonimplementsLetterPost{Overridepublicvoidwrite(Stringstr){System.out.println(write:str);}Overridepublicvoidsend(Stringaddresss){System.out.println(addr:addresss);}}classPostOffice{privateLetterPostletterPostnewLetterPost(){Overridepublicvoidwrite(Stringstr){System.out.println(write:str);}Overridepublicvoidsend(Stringaddresss){System.out.println(addr:addresss);}};publicvoidsendLetter(Stringtext,Stringaddr){letterPost.write(text);letterPost.send(addr);}}测试代码publicclassFacadeTest{publicstaticvoidtest(){PersonpersonnewPerson();person.write(hello);person.send(Nanjing);PostOfficeofficenewPostOffice();office.sendLetter(Hello,Nanjing);}}