zoukankan      html  css  js  c++  java
  • 设计模式_门面模式

    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大学");
     }
    }

    长处 
        灵活,封装,安全,降低依赖

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

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

    我是菜鸟,我在路上。

  • 相关阅读:
    NET控件关于Popup Win控件的使用介绍(消息提示控件)[转]
    .net从数据库二进制字段下载附件(文件),解决中文乱码
    测试页面的运行时间
    HashTable 遍历的两种方法
    100款国外xhtml+css模板(免费)
    在SharpDevolop中使用wix3制作中文安装包
    ASP.NET中的Session解析(一)
    兴奋,我的小站GBA365成长中
    泛型集合的序列化和反序列化
    asp.net mvc项目只能运行在iis根目录下吗?
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/6852191.html
Copyright © 2011-2022 走看看