8.4 GOF设计模式三: 外观模式 Facade
GOF设计模式三: 外观模式 Facade
“现有系统”功能强大、复杂,开发“新系统”需要用到其中一部分,但又要增加一部 分新功能,该怎么办?
4.1 Facade Pattern: Key Features
Intent
You want to simplify how to use an existing system. You need to define your own interface.
现有系统的接口比较复杂,你希望利用原有的功能重新定义新的接口
Problem
You need to use only a subset of a complex system. Or you need to interact with the system in
a particular way.
如果只希望使用现有系统的部分功能、或者以一 种特殊的方式与现有系统交互
Solution
The Facade presents a new interface for the client of the existing system to use.
外观模式提供一套新的接口供客户使用现有系统
Participants and collaborators
It presents a simplified interface to the client that makes it easier to use.
它呈 现给客户一套简单地接口,易于使用。
Consequences
The Facade simplifies the use of the required subsystem. However, because the Facade is
not complete, certain functionality may be unavailable to the client.
现有系统的部分功能,客户可能会不可用
Implementation
Define a new class (or classes) that has the required interface. Have this new class use the
existing system.
新定义的类,使用了现有系统的功能 ,为客户提供所需要的接口
4.1 Facade Pattern: Key Features
动机 Motivation
最小化通信 Minimize communication
最小化依赖 Minimize dependencies
4.2 外观模式的比喻 Non-software examples
例如,贸易公司的客户通过目录下订单,就类似一个“外观模式
客户联系公司的客户联系代表
客户联系代表 就作为“外观”,为客户提供接口,完成下单、付费、运 输等公司内部复杂的功能
客户很轻松完成任务
4.3 外观模式与适配器模式的比较
外观定义了新的接口,适配器使用旧的接口
Facade defines a new interface, whereas Adapter uses an old interface
适配器使得两个不一致的接口协同工作,而不是定义一个新的
Adapter makes two existing interfaces work together as opposed to defining an entirely new one
外观模式的本意是产生一个轻便的接口,适配器的本意是把现有的接口转换 一下
The intent of Facade is to produce a simpler interface, and the intent of Adapter is to design to
an existing interface
一个外观接口可能包装了多个现有系统的对象、也可能增加了一些新功能, 而适配器只是包装一个对象 While Facade routinely wraps multiple objects and Adapter wraps a single object
多数情况下,外观是单实例的
Facade objects are often Singletons because only one Facade object is required
GRASP原则的外观控制器,就是外观模式
4.4 适用性 Applicability
简化复杂系统的使用 Provide a simple interface to a complex subsystem
You do not need to use all the functionality of a complex system and can create a new class
that contains all the rules for accessing that system
If this is a subset of the original system, as it usually is, the API that you create for the new
class should be much simpler than the original system's API
在使用复杂系统的某个功能时,可以加入新功能
You want to use the functionality of the original system and want to add some new functionality as well
为客户软件层提供一个接口,隐藏了现有系统的细节
Provide an interface to a software layer
You want to encapsulate or hide the original system
使客户与现有系统之间减少耦合、增加独立性、可移植性
节约成本
开发新的外观类的成本,要比每个人都去熟悉现有系统、了解如何使用现有系统的功能 要节省许多
8.4 GOF设计模式三: 外观模式 Facade的更多相关文章
- 乐在其中设计模式(C#) - 外观模式(Facade Pattern)
原文:乐在其中设计模式(C#) - 外观模式(Facade Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 外观模式(Facade Pattern) 作者:webabcd 介绍 ...
- 二十四种设计模式:外观模式(Facade Pattern)
外观模式(Facade Pattern) 介绍为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用.示例有一个Message实体类,某对象对它 ...
- 设计模式之外观模式(Facade)摘录
23种GOF设计模式一般分为三大类:创建型模式.结构型模式.行为模式. 创建型模式抽象了实例化过程,它们帮助一个系统独立于怎样创建.组合和表示它的那些对象.一个类创建型模式使用继承改变被实例化的类,而 ...
- [设计模式] 10 外观模式 facade
外观模式应该是用的很多的一种模式,特别是当一个系统很复杂时,系统提供给客户的是一个简单的对外接口,而把里面复杂的结构都封装了起来.客户只需使用这些简单接口就能使用这个系统,而不需要关注内部复杂的结构. ...
- 设计模式 笔记 外观模式 Facade
//---------------------------15/04/16---------------------------- //Facade 外观模式-----对象结构型模式 /* 1:意图: ...
- 【设计模式】—— 外观模式Facade
前言:[模式总览]——————————by xingoo 模式意图 外观模式主要是为了为一组接口提供一个一致的界面.从而使得复杂的子系统与用户端分离解耦. 有点类似家庭常用的一键开关,只要按一个键,台 ...
- 结构型设计模式之外观模式(Facade)
结构 意图 为子系统中的一组接口提供一个一致的界面,F a c a d e 模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 适用性 当你要为一个复杂子系统提供一个简单接口时.子系统往往因 ...
- python : 设计模式之外观模式(Facade Pattern)
#为啥要用外观模式举例说明 这个例子很形象,直接从人家博客上贴过来的,参考链接在下面 不知道大家有没有比较过自己泡茶和去茶馆喝茶的区别,如果是自己泡茶需要自行准备茶叶.茶具和开水,如图1(A)所示,而 ...
- 【UE4 设计模式】外观模式 Facade Pattern
概述 描述 外部与一个子系统的通信必须通过一个统一的外观对象进行,为子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用.外观模式又称为门面模式,它是一 ...
随机推荐
- puppeteer(六)启动参数——浏览器扩展应用的添加及应用
前言 最近再做浏览器的自动化,首页是定制化的,是通过extension(扩展)实现的,由于通过puppeteer默认是以无参(即首次以干净的环境)运行的,导致登录页无法正常显示,首先想当然是直接找扩展 ...
- linux 基本原则和常用命令
Linux的基本原则:1.由目的单一的小程序组成,组合小程序完成复杂的功能:2.一切皆文件:3.尽量避免捕获用户接口:4.配置文件保存为纯文本格式. CLI接口的命令提示符:#(root)$(普通用户 ...
- 【转】Windons+jenkins,构建java程序,提示C:\Windows\TEMP\jenkins5037773887088486383.bat Access is denied
坑1: !!!前提:已设置本机电脑的账号密码, 解决方法:搜索程序services.msc-- 找到Jenkins-- 右键“属性”--登录--此账户--输入本机的账号密码--保存-- 停止Jenki ...
- python学习之爬虫初体验
作业来源: "https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2851" ** 1.简述爬虫原理 通用爬虫 即(搜索 ...
- tomcat部署项目
提示:指定jdk版本 在bin路径下的setclasspath.bat文件添加 set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_201 set JRE_HO ...
- ROS中使用Kinect摄像头和usb摄像头
1.安装的一些包 kinect用的freenect: $ sudo apt-get install ros-indigo-freenect-launch $ sudo apt-get install ...
- ajax基本用法介绍
使用ajax需要同时在模板中引用jQuery,ajax基本使用方法如下: $.ajax({ url:'url', type:'POST', data:{'k1':v1,'k2':v2,}, dataT ...
- 基于OpenCV做“三维重建”(3)--相机参数矩阵
通过前面的相机标定,我们能够获得一些参数模型.但是这些相机的参数矩阵到底是什么意思?怎样才能够判断是否正确?误差都会来自哪里?这里就必须要通过具体实验来加深认识.采集带相机参数的图片具有一定难度,幸好 ...
- 洲阁筛 & min_25筛学习笔记
洲阁筛 给定一个积性函数$F(n)$,求$\sum_{i = 1}^{n}F(n)$.并且$F(n)$满足在素数和素数次幂的时候易于计算. 显然有: $\sum_{i = 1}^{n} F(n) = ...
- SpringMVC,SpringBoot利用ajax上传文件到后台
1.传递单文件 首先html文件中有个<input type=”file” name=”file” id=”file”/>元素. 前台js写法: var formData=new Form ...