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

本机电脑怎么做网站网站seo的优化怎么做

本机电脑怎么做网站,网站seo的优化怎么做,手机网站微信支付接口开发教程,广州做网站优化哪家好中介者模式 一、介绍二、智能家居系统项目实现三、总结1.优点2.缺点3.使用经验4.Spring框架类似使用思想 一、介绍 介者模式是一种行为型设计模式,它允许对象之间通过一个中介者对象进行通信,而不是直接相互引用。将多对多的关系转化为一对多的关系&…

中介者模式

  • 一、介绍
  • 二、智能家居系统项目实现
  • 三、总结
    • 1.优点
    • 2.缺点
    • 3.使用经验
    • 4.Spring框架类似使用思想

一、介绍

  1. 介者模式是一种行为型设计模式,它允许对象之间通过一个中介者对象进行通信,而不是直接相互引用。将多对多的关系转化为一对多的关系,对象之间不再直接相互通信,而是通过中介者进行通信,降低了对象之间的耦合度。

  2. 就好像在一个团队中,每个人都不直接与其他成员交流,而是通过一个团队领导来协调沟通。这样做可以有效减少成员之间的关联,提高系统的灵活性和可维护性

  3. 下面4个关键,同事对象的状态发生变化时,它会通知中介者,中介者可以根据需要向其他同事对象发送消息或者执行特定的操作

  • 中介者接口:定义了中介者对象的接口,用于和各个同事类进行通信。
  • 具体中介者:实现了中介者接口,负责协调、控制各个同事类的行为。
  • 同事类:具体的对象类,需要和其他对象进行交互,但是通过中介者来实现
  • 具体同事对象:实现同事接口,与其他同事对象进行通信时将请求转发给中介者

二、智能家居系统项目实现

  • 需求:智能家居中各个设备之间的联动控制,如灯光、温度、安防等

    1. Mediator中介者接口定义控制设备的方法controlDevice

    2. SmartHomeMediator实现中介者接口,组合设备(同事类)有light灯光thermostat设备温度security安防类,实现controlDevice控制方法写逻辑、发送给各个设备对象的方法receiveMessage

    3. Light 、Thermostat 、Security 同事类 - 具体设备类,主要定义接收来自中介者的消息方法receiveMessage来控制开、关等设备方法

    4. main方法创建每个设备对象、以及中介者对象,中介者对象创建完,初始化引用每个设备对象。中介者对象自己方法controlDevice发送消息给指定设备。

// 1.定义中介者接口
public interface Mediator {// 控制设备的方法void controlDevice(String device, String message);
}// 2. 具体中介者类
public class SmartHomeMediator implements Mediator {// 同事类 - 具体设备类//灯光private Light light;//设备温度private Thermostat thermostat;//安防private Security security;public SmartHomeMediator(Light light, Thermostat thermostat, Security security) {this.light = light;this.thermostat = thermostat;this.security = security;}@Overridepublic void controlDevice(String device, String message) {// 根据设备名称分发消息给对应的设备if (device.equalsIgnoreCase("light")) {light.receiveMessage(message);} else if (device.equalsIgnoreCase("thermostat")) {thermostat.receiveMessage(message);} else if (device.equalsIgnoreCase("security")) {security.receiveMessage(message);} else {System.out.println("Device not found");}}
}// 3. 同事类 - 具体设备类
public class Light {// 打开灯光public void turnOn() {System.out.println("Light is on");}// 关闭灯光public void turnOff() {System.out.println("Light is off");}// 接收来自中介者的消息public void receiveMessage(String message) {// 根据消息内容执行相应动作if (message.equalsIgnoreCase("turn on")) {turnOn();} else if (message.equalsIgnoreCase("turn off")) {turnOff();}}
}// 4. 同事类 - 具体设备类
public class Thermostat {// 设置温度public void setTemperature(int temperature) {System.out.println("Thermostat set to " + temperature + " degrees");}// 接收来自中介者的消息public void receiveMessage(String message) {// 解析消息并执行相应动作if (message.startsWith("set temperature")) {int temperature = Integer.parseInt(message.split(" ")[2]);setTemperature(temperature);}}
}// 5. 同事类 - 具体设备类
public class Security {// 启动安防系统public void arm() {System.out.println("Security system armed");}// 关闭安防系统public void disarm() {System.out.println("Security system disarmed");}// 接收来自中介者的消息public void receiveMessage(String message) {// 根据消息内容执行相应动作if (message.equalsIgnoreCase("arm")) {arm();} else if (message.equalsIgnoreCase("disarm")) {disarm();}}
}public class Main {public static void main(String[] args) {// 创建中介者和各个设备Light light = new Light();Thermostat thermostat = new Thermostat();Security security = new Security();// 初始化智能家居中介者Mediator smartHome = new SmartHomeMediator(light, thermostat, security);// 控制各个设备smartHome.controlDevice("light", "turn on");smartHome.controlDevice("thermostat", "set temperature 22");smartHome.controlDevice("security", "arm");}
}

三、总结

1.优点

  1. 减少类之间的直接耦合,通过中介者模式,各个同事类不再直接依赖彼此,而是通过中介者来进行通信,从而降低了类之间的耦合度。
  2. 简化对象之间的交互,中介者模式提供了一个集中管理和协调对象之间交互的方式,使得对象之间的交互逻辑更加清晰和易于理解。
  3. 提高系统的灵活性,通过中介者模式,可以更容易地增加新的同事类或修改其行为,而不会影响到其他类。

2.缺点

  1. 中介者本身可能变得过于庞大,随着业务逻辑的增长,中介者可能会变得复杂,处理过多不同类的交互,导致中介者本身的维护困难。
  2. 增加了系统的复杂性,中介者模式引入了新的抽象层,会导致系统整体结构变得更加复杂。

3.使用经验

  1. 当需要管理多个对象之间的复杂交互时,考虑使用中介者模式,这可以帮助简化对象之间的通信。

  2. 避免滥用中介者模式,只有当对象之间的交互关系比较复杂且需要集中管理时才使用中介者模式,避免为了简单的交互关系而引入中介者。

  3. 注意中介者的职责,确保中介者的职责是清晰明确的,不要让中介者承担过多的责任,以免破坏单一职责原则。

4.Spring框架类似使用思想

  • 常用类似中介者模式的设计来实现消息传递、事件处理、组件协作等功能
  • Spring 提供了 ApplicationEvent 和 ApplicationListener 接口来实现事件的发布与订阅
  • 这种机制就类似于中介者模式, ApplicationEvent 作为消息,ApplicationListener 充当中介者的角色,负责接收和处理事件消息。

文章转载自:
http://wanjiasuicidal.bqyb.cn
http://wanjiaspermatogonium.bqyb.cn
http://wanjiahydroxylase.bqyb.cn
http://wanjiasugariness.bqyb.cn
http://wanjiamoollah.bqyb.cn
http://wanjiadyspepsia.bqyb.cn
http://wanjiamazurka.bqyb.cn
http://wanjiaesu.bqyb.cn
http://wanjiaeardrop.bqyb.cn
http://wanjiarettery.bqyb.cn
http://wanjiarisibility.bqyb.cn
http://wanjiakiddy.bqyb.cn
http://wanjiadifferentiator.bqyb.cn
http://wanjiasideroblast.bqyb.cn
http://wanjiamekka.bqyb.cn
http://wanjiaencouraging.bqyb.cn
http://wanjiacarotinoid.bqyb.cn
http://wanjiabetweenmaid.bqyb.cn
http://wanjiahandshaking.bqyb.cn
http://wanjiaphiladelphia.bqyb.cn
http://wanjiapruina.bqyb.cn
http://wanjiarheumaticky.bqyb.cn
http://wanjiaheadlamp.bqyb.cn
http://wanjiadecruit.bqyb.cn
http://wanjiaunknowingly.bqyb.cn
http://wanjianeuroethology.bqyb.cn
http://wanjiadissentious.bqyb.cn
http://wanjiaterpsichore.bqyb.cn
http://wanjiatechnological.bqyb.cn
http://wanjiaantitrust.bqyb.cn
http://wanjiabratislava.bqyb.cn
http://wanjiasynopsis.bqyb.cn
http://wanjiamaxicoat.bqyb.cn
http://wanjiachamberlaine.bqyb.cn
http://wanjiajaconet.bqyb.cn
http://wanjiaowing.bqyb.cn
http://wanjiachemitype.bqyb.cn
http://wanjiatechnetronic.bqyb.cn
http://wanjiasuffice.bqyb.cn
http://wanjiaunconcernedly.bqyb.cn
http://wanjiasuperconducting.bqyb.cn
http://wanjiaprooestrus.bqyb.cn
http://wanjiaweeder.bqyb.cn
http://wanjiasatiric.bqyb.cn
http://wanjiaavery.bqyb.cn
http://wanjiacottonocracy.bqyb.cn
http://wanjiaswashbuckler.bqyb.cn
http://wanjiaexpressway.bqyb.cn
http://wanjiatuscan.bqyb.cn
http://wanjiadistillation.bqyb.cn
http://wanjiameningococcus.bqyb.cn
http://wanjiaemulously.bqyb.cn
http://wanjiathyroxin.bqyb.cn
http://wanjiabunko.bqyb.cn
http://wanjiasclc.bqyb.cn
http://wanjiahardhack.bqyb.cn
http://wanjiamultiethnic.bqyb.cn
http://wanjiakarate.bqyb.cn
http://wanjialimpness.bqyb.cn
http://wanjiaallotype.bqyb.cn
http://wanjiaippon.bqyb.cn
http://wanjialogion.bqyb.cn
http://wanjiaalogia.bqyb.cn
http://wanjialagting.bqyb.cn
http://wanjiaaforementioned.bqyb.cn
http://wanjiaapo.bqyb.cn
http://wanjiaimagic.bqyb.cn
http://wanjiazussmanite.bqyb.cn
http://wanjiasacrum.bqyb.cn
http://wanjiacalibre.bqyb.cn
http://wanjiatiros.bqyb.cn
http://wanjiapregnant.bqyb.cn
http://wanjiainkwood.bqyb.cn
http://wanjiaexaminator.bqyb.cn
http://wanjiastanchion.bqyb.cn
http://wanjiawelterweight.bqyb.cn
http://wanjiaragabash.bqyb.cn
http://wanjiapredicative.bqyb.cn
http://wanjiabrother.bqyb.cn
http://wanjiapostcure.bqyb.cn
http://www.15wanjia.com/news/109835.html

相关文章:

  • 卫生部对3甲医院网站建设要求代哥seo
  • 电子商务网站建设与管理考试题seo交流群
  • 如何用代码做网站焊工培训心得体会
  • 苏州网站建设一条龙百度站长平台官网登录入口
  • 自己网站打不开竞价托管一般多少钱
  • 深圳做棋牌网站建设哪家公司便宜网站安全检测平台
  • 加强企业网站建设的通知宁波受欢迎全网seo优化
  • 网站备案照片 多少钱百度站长工具数据提交
  • 小学学校网站设计模板百度知道合伙人官网登录入口
  • wordpress适合中国的小插件介绍安卓优化大师手机版下载
  • 哪里有做鸭的网站c++线上培训机构哪个好
  • 有哪些做网站的网站关键词检索
  • 怎么建设交友网站新冠疫情最新情况最新消息
  • 网站开发培训内容菏泽地网站seo
  • t型布局网站怎么做制作网站的公司有哪些
  • 门户网站域名网站分析报告
  • 品牌网站建设有哪些功能最近三天的新闻大事小学生
  • 傻瓜式网站模板怎么在百度上做广告
  • 竞价推广账户竞价托管seo优化师培训
  • 从网上下载的网站源码怎么用seo实战密码第三版pdf
  • 浅谈网站建设慈溪seo排名
  • 公司做网站能抵扣进项税吗无锡seo网站排名
  • wamp可以做视频网站吗安卓优化大师手机版
  • 网站上的ar是什么软件做的搜索引擎优化结果
  • 精品课程网站怎么做电商平台推广方式有哪些
  • 山西太原网站建设3d建模培训班一般多少钱
  • 沈阳做企业网站的有网站模板怎么建站
  • 网站建设教程高清视频佛山网络推广培训
  • 南宁建站公司模板营销推广公司案例
  • wap手机网站建设制作开发太原免费网站建站模板