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

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

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

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

    我是菜鸟,我在路上。

  • 相关阅读:
    [转载]C# 判断字符是否中文还是英文
    [转载]C#读写配置文件(XML文件)
    [转载]C#多线程学习(一) 多线程的相关概念
    [转载]C# HashTable 遍历与排序
    [转载]C# 多选功能(checkedListBox控件)
    [转载]在C#中使用官方驱动操作MongoDB
    [转载]MongoDB开发学习(2)索引的基本操作
    公钥私钥和RSA算法
    iOS 如何在一个已经存在多个project的workspace中引入cocoapods管理第三方类库
    应用号
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/6852191.html
Copyright © 2011-2022 走看看