|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
恩~~ 什么也就不说啦! 就直接上代码吧!
- /**
- * 门面模式
- */
- interface LetterProcess
- {
- //首先要写信的内容
- public void writeCOntext(String context);
- //其次写信封
- public void fillEnvelope(String address);
- //把信放在信封里
- public void letterInotoEnvelope();
- //然后投递
- public void sendLetter();
- }
- class LetterProcessImpl implements LetterProcess
- {
- //写信
- public void writeCOntext(String context)
- {
- System.out.println("填写信的内容..."+context);
- }
- //其次写信封
- public void fillEnvelope(String address)
- {
- System.out.println("填写收件人的地址及姓名"+address);
- }
- //把信放在信封里
- public void letterInotoEnvelope()
- {
- System.out.println("把信放到信封中...");
- }
- //然后投递
- public void sendLetter()
- {
- System.out.println("邮递信件...");
- }
- }
- class ModenPostOffice
- {
- private LetterProcess letterProcess = new LetterProcessImpl();
- //写信,封装,投递,一体化
- public void sendLetter(String context, String address)
- {
- //首先要写信的内容
- letterProcess.writeCOntext(context);
- //其次写信封
- letterProcess.fillEnvelope(address);
- //把信放在信封里
- letterProcess.letterInotoEnvelope();
- //然后投递
- letterProcess.sendLetter();
- }
- }
- public class FacadePattern
- {
- public static void main(String[] args)
- {
- ModenPostOffice modenPostOffice = new ModenPostOffice();
- //只要把信的内容和收件人地址给他,他会帮你完成
- String address = "北京市海淀区西小口";
- String context = "你好! 我是小白马!";
-
- modenPostOffice.sendLetter(context,address);
- }
- }
复制代码
|
|