首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

Facade-门脸模式

2013-02-24 
Facade--门面模式interface LetterProcess {public void writeContext(String context)public void fillE

Facade--门面模式

interface LetterProcess {public void writeContext(String context);public void fillEnvelope(String address);public void letterIntoEnvelope();public void sendLetter();}class PersonWriteLetter implements LetterProcess {@Overridepublic void writeContext(String context) {// TODO Auto-generated method stubSystem.out.println("write the context:" + context);}@Overridepublic void fillEnvelope(String address) {// TODO Auto-generated method stubSystem.out.println("fill Envelope with address:" + address);}@Overridepublic void letterIntoEnvelope() {// TODO Auto-generated method stubSystem.out.println("put letter into Envelope");}@Overridepublic void sendLetter() {// TODO Auto-generated method stubSystem.out.println("send letter");}}public class Facade {LetterProcess letterProcess = new PersonWriteLetter();Police police = new Police();public void sendLetter(String context, String address) {letterProcess.writeContext(context);letterProcess.fillEnvelope(address);letterProcess.letterIntoEnvelope();//任何对LetterPress操作的过程可以放在门面中。如,警察检查信件police.checkLetter(letterProcess);letterProcess.sendLetter();};}class Police{void checkLetter(LetterProcess letterProcess){}}



/** * 4.门面模式Facade */System.out.println("***********4.门面模式***********");Facade facade = new Facade();facade.sendLetter("I Love u", "No.5 Street");

热点排行