鱼C论坛

 找回密码
 立即注册
查看: 1979|回复: 0

java设计模式之门面模式

[复制链接]
发表于 2015-1-21 12:19:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
恩~~ 什么也就不说啦! 就直接上代码吧!

  1. /**
  2. * 门面模式
  3. */
  4. interface LetterProcess
  5. {
  6.   //首先要写信的内容
  7.   public void writeCOntext(String context);
  8.   //其次写信封
  9.   public void fillEnvelope(String address);
  10.   //把信放在信封里
  11.   public void letterInotoEnvelope();
  12.   //然后投递
  13.   public void sendLetter();
  14. }

  15. class LetterProcessImpl implements LetterProcess
  16. {
  17.   //写信
  18.   public void writeCOntext(String context)
  19.   {
  20.     System.out.println("填写信的内容..."+context);
  21.   }
  22.   //其次写信封
  23.   public void fillEnvelope(String address)
  24.   {
  25.     System.out.println("填写收件人的地址及姓名"+address);
  26.   }

  27.   //把信放在信封里
  28.   public void letterInotoEnvelope()
  29.   {
  30.       System.out.println("把信放到信封中...");
  31.   }
  32.    //然后投递
  33.   public void sendLetter()
  34.   {
  35.     System.out.println("邮递信件...");
  36.   }


  37. }

  38. class ModenPostOffice
  39. {
  40.   private  LetterProcess letterProcess = new LetterProcessImpl();

  41.   //写信,封装,投递,一体化
  42.   public void sendLetter(String context, String address)
  43.   {
  44.     //首先要写信的内容
  45.    letterProcess.writeCOntext(context);
  46.    //其次写信封
  47.    letterProcess.fillEnvelope(address);
  48.    //把信放在信封里
  49.    letterProcess.letterInotoEnvelope();
  50.    //然后投递
  51.    letterProcess.sendLetter();

  52.   }
  53. }

  54. public class FacadePattern
  55. {
  56.   public static void main(String[] args)
  57.   {
  58.      ModenPostOffice modenPostOffice = new ModenPostOffice();
  59.      //只要把信的内容和收件人地址给他,他会帮你完成
  60.      String address = "北京市海淀区西小口";
  61.      String context = "你好! 我是小白马!";
  62.      
  63.      modenPostOffice.sendLetter(context,address);
  64.   }
  65. }
复制代码
2015-01-21 12:17:33 的屏幕截图.png


本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 05:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表