设计模式_门面模式

Facade Pattern
     Provide a unified interface to a set of interfaces in a subsystem.Facade defines a higher-level interface that makes the subsystem easier to use.(要求一个子系统的外部与其内部的通信必须通过一个统一的对象进行,门面模式提供一个高层次的接口,使得子系统更易于使用)

为什么这也算一种设计模式? 

public interface ILetterProcess {
 public void writerContext(String context);
 public void fillEnvelope(String address);
 public void letterIntoEnvelope();
 public void sendLetter();
}

public class LetterProcess implements ILetterProcess {
 public void fillEnvelope(String address) {
  System.out.println("填写信的地址:"+address);
 }
 public void letterIntoEnvelope() {
  System.out.println("把信放进信封");
 }
 public void sendLetter() {
  System.out.println("邮递信件");
 }
 public void writerContext(String context) {
  System.out.println("写信内容:"+context);
 }
}

public class ModenPostOffice {
 private ILetterProcess letterProcess=new LetterProcess();
 
 public void sendLetter(String context,String address){
  this.letterProcess.writerContext(context);
  this.letterProcess.fillEnvelope(address);
  this.letterProcess.letterIntoEnvelope();
  this.letterProcess.sendLetter();
 }
}

public class Client {
 
 public static void main(String[] args) {
  ModenPostOffice postOffice=new ModenPostOffice();
  postOffice.sendLetter("你被录取了", "XX大学");
 }
}

优点 
    灵活,封装,安全,减少依赖

缺点
    不符合开闭原则,没办法扩展

使用场景
    为一个复杂子系统或者模块提供一个外界访问的接口
    子系统相对独立
    预防一个低水平的技术人员参与项目开发,为降低个人代码质量对整体项目的影响风险

我是菜鸟,我在路上。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值