LetterProcess.java代码如下:
package com.designPattern.facade;
public interface LetterProcess {
public void writeContext(String context);
public void fillEnvelope(String address);
public void letterIntoEnvelope();
public void sendLetter();
}
LetterProcessImpl.java代码如下:
package com.designPattern.facade;
public class LetterProcessImpl implements LetterProcess{
public void writeContext(String context) {
System.out.println("填写信的内容:"+context);
}
public void fillEnvelope(String address) {
System.out.println("填写收件人地址及姓名:"+address);
}
public void letterIntoEnvelope() {
System.out.println("把信放到信封中!");
}
public void sendLetter() {
System.out.println("邮递信件!");
}
}
ModenPostOffice.java代码如下:
package com.designPattern.facade;
/**
* 门面模式类
* @author yangjianzhou
*
*/
public class ModenPostOffice {
private LetterProcess letterProcess = new LetterProcessImpl();
public void sendLetter(String context,String address){
letterProcess.writeContext(context);
letterProcess.fillEnvelope(address);
letterProcess.letterIntoEnvelope();
letterProcess.sendLetter();
}
}
Client.java代码如下:
package com.designPattern.facade;
public class Client {
public static void main(String[] args) {
ModenPostOffice modenPostOffice = new ModenPostOffice();
String context = " hello , this is my first letter to you !";
String address = " shanghai songjiang ";
modenPostOffice.sendLetter(context, address);
}
}
运行结果如下:
填写信的内容: hello , this is my first letter to you !
填写收件人地址及姓名: shanghai songjiang
把信放到信封中!
邮递信件!