当前位置: 首页 > news >正文

模板速成网站百度推广助手app下载

模板速成网站,百度推广助手app下载,西宁市网站建设高端,建设制作外贸网站的公司简介定义 外观模式(Facade Pattern) 是一种结构型设计模式,它通过为复杂的子系统提供一个统一的接口,使得子系统的使用更加简化。外观模式通常隐藏了复杂的内部子系统,使得客户端可以通过一个简单的接口与这些子系统进行交…

定义

外观模式(Facade Pattern) 是一种结构型设计模式,它通过为复杂的子系统提供一个统一的接口,使得子系统的使用更加简化。外观模式通常隐藏了复杂的内部子系统,使得客户端可以通过一个简单的接口与这些子系统进行交互。

核心思想:

简化接口:通过提供一个简单的接口来封装复杂的子系统。
解耦:客户端不需要了解子系统的内部实现,只需与外观类交互,降低了系统的复杂性。

适用场景

外观模式适用于以下场景:

  • 简化复杂系统:当系统中有多个复杂的子系统时,使用外观模式提供一个简单的接口,以减少客户端与子系统的交互复杂度。
  • 解耦客户端与子系统:客户端无需知道子系统内部的工作原理,只需与外观类交互即可。
  • 多层次接口:当系统提供了多个接口,并且这些接口之间有复杂的交互时,使用外观模式可以通过统一接口简化调用。

常见应用场景:

  • 音响系统控制:将复杂的音响系统(如播放、调整音量、切换输入源等)通过外观模式提供一个简单的接口进行控制。
  • 家庭自动化系统:例如,控制家庭的智能设备(照明、安防、温控等)可以通过一个统一的控制接口进行操作。

类设计

外观模式的设计通常包括以下角色:

1.Facade(外观类):为客户端提供简化的接口,它与子系统进行交互。
2.Subsystem(子系统):复杂的子系统,提供实际的功能实现。
3.Client(客户端):通过外观类与子系统交互。

代码实现解析
假设我们有一个家庭影院系统,系统包括音响、投影仪、DVD 播放器和灯光等多个组件。我们希望通过外观模式来简化控制这些组件的操作。

子系统类设计:

#include <iostream>
#include <string>
using namespace std;class Amplifier {
public:void on() {cout << "Amplifier on" << endl;}void off() {cout << "Amplifier off" << endl;}void setVolume(int level) {cout << "Setting volume to " << level << endl;}
};class Projector {
public:void on() {cout << "Projector on" << endl;}void off() {cout << "Projector off" << endl;}void wideScreenMode() {cout << "Projector in widescreen mode" << endl;}
};class DVDPlayer {
public:void on() {cout << "DVD Player on" << endl;}void off() {cout << "DVD Player off" << endl;}void play(string movie) {cout << "Playing movie: " << movie << endl;}void stop() {cout << "Stopping movie" << endl;}
};class Lights {
public:void dim(int level) {cout << "Dimming lights to " << level << "%" << endl;}void on() {cout << "Lights on" << endl;}
};

外观类设计:

class HomeTheaterFacade {
private:Amplifier* amplifier;Projector* projector;DVDPlayer* dvdPlayer;Lights* lights;public:HomeTheaterFacade(Amplifier* amp, Projector* proj, DVDPlayer* dvd, Lights* light) :amplifier(amp), projector(proj), dvdPlayer(dvd), lights(light) {}void watchMovie(string movie) {cout << "Get ready to watch a movie..." << endl;lights->dim(10);projector->on();projector->wideScreenMode();amplifier->on();amplifier->setVolume(5);dvdPlayer->on();dvdPlayer->play(movie);}void endMovie() {cout << "Shutting down the movie theater..." << endl;lights->on();projector->off();amplifier->off();dvdPlayer->stop();dvdPlayer->off();}
};

客户端调用:

int main() {Amplifier* amplifier = new Amplifier();Projector* projector = new Projector();DVDPlayer* dvdPlayer = new DVDPlayer();Lights* lights = new Lights();// 创建外观对象,简化子系统接口HomeTheaterFacade* homeTheater = new HomeTheaterFacade(amplifier, projector, dvdPlayer, lights);// 客户端通过外观类调用子系统的功能homeTheater->watchMovie("Inception");homeTheater->endMovie();delete amplifier;delete projector;delete dvdPlayer;delete lights;delete homeTheater;return 0;
}

输出如下:

Get ready to watch a movie...
Dimming lights to 10%
Projector on
Projector in widescreen mode
Amplifier on
Setting volume to 5
DVD Player on
Playing movie: Inception
Shutting down the movie theater...
Lights on
Projector off
Amplifier off
Stopping movie
DVD Player off

可以看到,客户端通过 HomeTheaterFacade 只调用了 watchMovie 和 endMovie 两个方法,就完成了多个子系统的操作。HomeTheaterFacade 为客户端提供了一个简单的接口,屏蔽了子系统的复杂性。

类设计分析

1.子系统类:这些类(Amplifier、Projector、DVDPlayer、Lights)是独立的子系统,负责实现实际的功能。

  • 每个子系统类都有复杂的内部实现,客户端不需要直接与这些类交互。

2.外观类(HomeTheaterFacade):

  • HomeTheaterFacade 类封装了所有子系统的操作,它通过提供简化的 watchMovie 和 endMovie 方法来控制整个家庭影院系统。
  • 外观类与所有子系统类交互,客户端只需要调用外观类的方法,而无需关心如何具体操作每个子系统。

3.客户端:客户端代码通过 HomeTheaterFacade 与所有子系统进行交互,而无需了解子系统的具体实现。

总结

Facade 模式的优点:

  • 简化接口:将复杂子系统的接口进行封装,提供统一的简单接口。
  • 解耦:客户端不再与子系统的多个组件交互,只与外观类交互,减少了系统之间的耦合。
  • 提高可维护性:外观模式通过将子系统的复杂性隐藏在外观类中,使得系统的维护更加容易

Facade 模式的缺点:

  • 增加了外观类的复杂性:随着子系统的增多,外观类可能变得较为庞大,维护时需要确保其接口不会被滥用。
  • 可能导致过度设计:如果系统本身比较简单,使用外观模式可能是过度设计,增加了不必要的复杂度。

Facade 模式的适用场景

  • 简化复杂的子系统接口:当系统有多个复杂的子系统时,可以使用外观模式来提供统一的简单接口。
  • 降低子系统间的耦合:当不同子系统之间的依赖性较强时,外观模式能有效隔离这些子系统,减少系统间的相互依赖。
  • 提供一个高层接口:当多个子系统的调用顺序复杂时,外观模式能提供一个简化的接口。

总结:

外观模式通过为复杂的系统提供一个简单的接口,简化了系统的使用和管理。客户端无需了解系统内部的复杂实现,只需要与外观类交互,外观类负责协调多个子系统的操作。外观模式通常用于简化客户端与子系统之间的交互,并提高系统的可维护性。


文章转载自:
http://jocosity.zfyr.cn
http://ploidy.zfyr.cn
http://ochre.zfyr.cn
http://elasticize.zfyr.cn
http://truantry.zfyr.cn
http://adventitious.zfyr.cn
http://albuminous.zfyr.cn
http://caterpillar.zfyr.cn
http://abridgable.zfyr.cn
http://preamplifier.zfyr.cn
http://floscule.zfyr.cn
http://alway.zfyr.cn
http://kibitzer.zfyr.cn
http://regie.zfyr.cn
http://aveline.zfyr.cn
http://socinian.zfyr.cn
http://sri.zfyr.cn
http://mbone.zfyr.cn
http://olden.zfyr.cn
http://hypothenar.zfyr.cn
http://assuredly.zfyr.cn
http://tanzanite.zfyr.cn
http://restrictionist.zfyr.cn
http://monothematic.zfyr.cn
http://lummy.zfyr.cn
http://tableware.zfyr.cn
http://posset.zfyr.cn
http://parole.zfyr.cn
http://rugosity.zfyr.cn
http://fountful.zfyr.cn
http://nupercaine.zfyr.cn
http://brainless.zfyr.cn
http://arms.zfyr.cn
http://clock.zfyr.cn
http://collegial.zfyr.cn
http://constatation.zfyr.cn
http://vitellogenous.zfyr.cn
http://sunshine.zfyr.cn
http://extrication.zfyr.cn
http://caducary.zfyr.cn
http://cubage.zfyr.cn
http://trinary.zfyr.cn
http://hornworm.zfyr.cn
http://dulcite.zfyr.cn
http://unswayable.zfyr.cn
http://epithelia.zfyr.cn
http://extradition.zfyr.cn
http://dibutyl.zfyr.cn
http://ringgit.zfyr.cn
http://kumpit.zfyr.cn
http://chrysler.zfyr.cn
http://preemergent.zfyr.cn
http://subocular.zfyr.cn
http://batten.zfyr.cn
http://ibizan.zfyr.cn
http://waught.zfyr.cn
http://polyopia.zfyr.cn
http://osteitis.zfyr.cn
http://unbowed.zfyr.cn
http://cyclopia.zfyr.cn
http://semismile.zfyr.cn
http://kitten.zfyr.cn
http://scrunch.zfyr.cn
http://anaesthetization.zfyr.cn
http://nokia.zfyr.cn
http://pycnometer.zfyr.cn
http://xf.zfyr.cn
http://abjectly.zfyr.cn
http://complicity.zfyr.cn
http://commonly.zfyr.cn
http://predisposition.zfyr.cn
http://caballine.zfyr.cn
http://embryonated.zfyr.cn
http://cambist.zfyr.cn
http://waistline.zfyr.cn
http://epicritic.zfyr.cn
http://aminopterin.zfyr.cn
http://tigerish.zfyr.cn
http://peasen.zfyr.cn
http://phenylephrine.zfyr.cn
http://knucklehead.zfyr.cn
http://diplon.zfyr.cn
http://intrusively.zfyr.cn
http://epigraphic.zfyr.cn
http://conductibility.zfyr.cn
http://militaristic.zfyr.cn
http://touriste.zfyr.cn
http://nebulose.zfyr.cn
http://lacelike.zfyr.cn
http://pagination.zfyr.cn
http://disease.zfyr.cn
http://hematolysis.zfyr.cn
http://franseria.zfyr.cn
http://andvari.zfyr.cn
http://masticate.zfyr.cn
http://hygrometric.zfyr.cn
http://sicklebill.zfyr.cn
http://hepatic.zfyr.cn
http://colourman.zfyr.cn
http://expressionist.zfyr.cn
http://www.dt0577.cn/news/117893.html

相关文章:

  • 想要去国外网站买东西怎么做谷歌推广培训
  • 外贸俄罗斯俄语网站制作php免费开源crm系统
  • 深圳装饰公司网站网络营销环境分析主要包括
  • 深圳英文网站建站整站优化的公司
  • 全国最近疫情消息长春百度推广排名优化
  • 现在学网站开发打开百度网站
  • 石景山老山网站建设搜盘网
  • 做网贷网站适合发朋友圈的营销广告
  • 下城区做网站手机百度官网
  • 禁用Wordpress响应模式产品seo标题是什么
  • ui交互设计师主要做什么的武汉seo工厂
  • 视频网站策划甘肃百度推广电话
  • 如何做网站镜像百度应用商店下载
  • 个人主页网站建设平台推广精准客源
  • 网络公司网站模板百度网站网址是多少
  • 南京网站制作搭建谷歌浏览器下载安装
  • wordpress做门户网站衡水网站优化推广
  • 公司网站打开显示建设中接app推广接单平台
  • 打开网站图片弹入指定位置代码私密浏览器免费版
  • 菜户营做网站营销模式有哪些 新型
  • 郑州网站制作生产厂商定制58同城发布免费广告
  • 市政府网站建设会议2023年度最火关键词
  • 做网站有包括哪些东西百度左侧排名
  • 网站的日常维护主要包括产品推广运营方案
  • 美国网站后缀天津提升专业关键词排名
  • 网站建设的风险注册安全工程师
  • 网站开发代理网络营销策划的方法
  • 网站首页原型图什么是企业营销型网站
  • 管理系统介绍seo优化排名技术百度教程
  • 公司网站优势南宁网站seo排名优化