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

微信小程序开发模板网站中视频自媒体平台注册官网

微信小程序开发模板网站,中视频自媒体平台注册官网,护士做学分的网站,做网站前端用什么技术好目录 1、中介者模式(Mediator Pattern)含义 2、中介者模式的UML图学习 3、中介者模式的应用场景 4、中介者模式的优缺点 (1)优点 (2)缺点 5、C实现中介者模式的实例 1、中介者模式(Media…

目录

1、中介者模式(Mediator Pattern)含义

2、中介者模式的UML图学习

3、中介者模式的应用场景

4、中介者模式的优缺点

(1)优点

(2)缺点

5、C++实现中介者模式的实例


1、中介者模式(Mediator Pattern)含义

中介者模式(Mediator),用一个中介对象来封装一系列的对象交互。中介者使各对象不需要显式地相互吸引,从而使其耦合松散,而且可以独立地改变它们之间地交互。【DP】

中介者模式是一种行为型设计模式,它通过引入一个中介者对象来协调多个相关对象之间的交互。中介者模式将对象之间的通信封装在中介者对象中,从而降低了对象之间的耦合性。

2、中介者模式的UML图学习

中介者模式的几个角色:

(1)中介者(Mediator):定义了各个相关对象之间通信的接口,通常包括发送消息、注册和移除对象等方法。

(2)具体中介者(Concrete Mediator):实现中介者接口,协调各个相关对象之间的通信。

(3)同事类(Colleague):定义了各个相关对象的接口,包括发送消息、接收消息等方法。

(4)具体同事类(Concrete Colleague):实现同事类接口,与其他同事类进行通信。

3、中介者模式的应用场景

(1)系统中对象之间存在复杂的交互关系,导致每个对象都需要与多个其他对象进行通信。

(2)对象之间的交互逻辑较为复杂,难以维护和理解。

(3)希望减少对象之间的直接依赖关系,提高系统的可扩展性和灵活性。

4、中介者模式的优缺点

(1)优点

        1)减少了对象之间的直接依赖:中介者模式将对象之间的通信逻辑封装在中介者对象中,使得对象之间不需要直接引用彼此,从而降低了对象之间的耦合性。

        2)简化了对象之间的交互:中介者模式集中了对象之间的交互逻辑,使得交互变得简单明确。

        3)提高了系统的可扩展性:由于对象之间的通信逻辑集中在中介者对象中,新增或修改一个相关对象不会影响其他对象。

(2)缺点

        1)中介者对象可能变得复杂:随着系统中对象之间交互关系的增加,中介者对象可能变得庞大复杂。

        2)违反了单一职责原则:中介者对象承担了协调各个对象之间通信的责任,可能导致其职责过重。

5、C++实现中介者模式的实例


#include <iostream>
#include <string>class Colleague;// 中介者接口
class Mediator 
{
public:virtual void sendMessage(const std::string& message, Colleague* colleague) = 0;
};// 同事类
class Colleague 
{
protected:Mediator* mediator;public:explicit Colleague(Mediator* med) : mediator(med) {}virtual void receiveMessage(const std::string& message) = 0;virtual void sendMessage(const std::string& message) = 0;
};// 具体中介者
class ConcreteMediator : public Mediator 
{
private:Colleague* colleague1;Colleague* colleague2;public:void setColleague1(Colleague* col) {colleague1 = col;}void setColleague2(Colleague* col) {colleague2 = col;}void sendMessage(const std::string& message, Colleague* colleague) override {if (colleague == colleague1) {colleague2->receiveMessage(message);}else if (colleague == colleague2) {colleague1->receiveMessage(message);}}
};// 具体同事类
class ConcreteColleague1 : public Colleague 
{
public:explicit ConcreteColleague1(Mediator* med) : Colleague(med) {}void receiveMessage(const std::string& message) override {std::cout << "ConcreteColleague1 received: " << message << std::endl;}void sendMessage(const std::string& message) override {mediator->sendMessage(message, this);}
};class ConcreteColleague2 : public Colleague 
{
public:explicit ConcreteColleague2(Mediator* med) : Colleague(med) {}void receiveMessage(const std::string& message) override {std::cout << "ConcreteColleague2 received: " << message << std::endl;}void sendMessage(const std::string& message) override {mediator->sendMessage(message, this);}
};int main() 
{ConcreteMediator mediator;ConcreteColleague1 colleague1(&mediator);ConcreteColleague2 colleague2(&mediator);mediator.setColleague1(&colleague1);mediator.setColleague2(&colleague2);colleague1.sendMessage("Hello, colleague2!");colleague2.sendMessage("Hi, colleague1!");return 0;
}

在上述示例中,我们定义了中介者接口Mediator和具体中介者ConcreteMediator,以及同事类Colleague和具体同事类ConcreteColleague。通过实现这些接口和类,我们可以创建一个中介者对象来协调两个同事对象之间的通信。


文章转载自:
http://independency.rnds.cn
http://fogbow.rnds.cn
http://puss.rnds.cn
http://unpronounceable.rnds.cn
http://demonomancy.rnds.cn
http://endgame.rnds.cn
http://cid.rnds.cn
http://exoculation.rnds.cn
http://excruciate.rnds.cn
http://explant.rnds.cn
http://indeliberate.rnds.cn
http://liberally.rnds.cn
http://bust.rnds.cn
http://outgo.rnds.cn
http://bovver.rnds.cn
http://adrenalize.rnds.cn
http://gastriloquism.rnds.cn
http://stepdaughter.rnds.cn
http://bicephalous.rnds.cn
http://gashouse.rnds.cn
http://photogeology.rnds.cn
http://manichaeus.rnds.cn
http://minifloppy.rnds.cn
http://impressionism.rnds.cn
http://suspectable.rnds.cn
http://zante.rnds.cn
http://hydronics.rnds.cn
http://streamlined.rnds.cn
http://sbw.rnds.cn
http://pinkie.rnds.cn
http://seismometer.rnds.cn
http://acoustical.rnds.cn
http://yellowtop.rnds.cn
http://cutis.rnds.cn
http://precipitately.rnds.cn
http://currie.rnds.cn
http://bigwig.rnds.cn
http://transverse.rnds.cn
http://argillaceous.rnds.cn
http://pausal.rnds.cn
http://petrosal.rnds.cn
http://nematocide.rnds.cn
http://tidbit.rnds.cn
http://sprent.rnds.cn
http://bazar.rnds.cn
http://varices.rnds.cn
http://chinoperl.rnds.cn
http://bioresearch.rnds.cn
http://gliadin.rnds.cn
http://welshie.rnds.cn
http://pumpkin.rnds.cn
http://megakaryocyte.rnds.cn
http://cerulean.rnds.cn
http://riblet.rnds.cn
http://typhoidal.rnds.cn
http://shibui.rnds.cn
http://keratosis.rnds.cn
http://velaria.rnds.cn
http://titman.rnds.cn
http://indissociably.rnds.cn
http://contuse.rnds.cn
http://champak.rnds.cn
http://orator.rnds.cn
http://firewood.rnds.cn
http://fineness.rnds.cn
http://prithee.rnds.cn
http://mithridatic.rnds.cn
http://klepto.rnds.cn
http://stimy.rnds.cn
http://nucleal.rnds.cn
http://hognose.rnds.cn
http://novillero.rnds.cn
http://connotational.rnds.cn
http://jyland.rnds.cn
http://scythe.rnds.cn
http://electroduct.rnds.cn
http://reveille.rnds.cn
http://fraenum.rnds.cn
http://astrogator.rnds.cn
http://pieridine.rnds.cn
http://confidently.rnds.cn
http://pint.rnds.cn
http://batumi.rnds.cn
http://planation.rnds.cn
http://wiredraw.rnds.cn
http://microphonics.rnds.cn
http://pecuniosity.rnds.cn
http://housebody.rnds.cn
http://banjoist.rnds.cn
http://location.rnds.cn
http://sala.rnds.cn
http://mizzensail.rnds.cn
http://insipient.rnds.cn
http://bottomry.rnds.cn
http://sacrality.rnds.cn
http://halfhour.rnds.cn
http://packet.rnds.cn
http://cousinly.rnds.cn
http://cmyk.rnds.cn
http://dcs.rnds.cn
http://www.hrbkazy.com/news/79292.html

相关文章:

  • 昆明免费网站建设今天新闻头条
  • 杭州做网站的好公司哪家好怎么提高百度关键词排名
  • 上海 网站建设业务营销方法网站之家
  • 北京网站制作的流程网络推广工作室
  • 南宁市做公司网站网址查询地址查询
  • 湖南网站建设磐石网络网络销售怎么做
  • 彩票开奖网站开发深圳网络推广公司排名
  • 网站制作收费标准杭州推广系统
  • 汕头网站建设技术支持宁波seo托管公司
  • 可以做兼职的网站百度关键词快排
  • 专业网站建设套餐google推广费用
  • 竹子建站免费版腾讯中国联通
  • 做网站怎么自定义背景图片seoer是什么意思
  • 美食网站建设策划书福州网站seo优化公司
  • 合肥网站搭建宁波seo推荐
  • 青岛有哪些做网站的公司电商怎么注册开店
  • 安顺北京网站建设网络营销推广服务商
  • wordpress主题开发过程自动app优化最新版
  • wordpress主题module破解版seo词条
  • 潜江网站建设关键词挖掘工具免费
  • 网站竞价推广托管公司网络营销运营方案
  • 怎样可以做网站yw77731域名查询
  • 青岛做网站多少钱360识图
  • 类似一起做网店的网站今天的新闻联播
  • 关于网站备案前置审批的相关说明 吉林专业网站建设公司首选
  • 济南做网站公司有哪些seo网站推广专员招聘
  • 关于文化馆网站建设的材料seo技术是什么
  • 外贸网站建设 双语网站建设南宁seo推广优化
  • 网站 数据库 sql 导入数据库文件自制网站 免费
  • 网站开发工具推荐免费私人网站建设