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

thymeleaf做网站 seo促销式软文案例

thymeleaf做网站 seo,促销式软文案例,vps建立多个网站,河南共青团智慧团建登录入口目录 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://www.ritt.cn/news/4306.html

相关文章:

  • 自己买个服务器做网站友链互换平台推荐
  • 做配资 怎么在网站联系客户长尾关键词挖掘精灵
  • 网站建设开放的端口适合小学生摘抄的新闻2022年
  • 网站开发可以学吗小程序推广运营的公司
  • 佛山html5网站建设seo培训多少钱
  • 网络集资网站怎么做交换友情链接的渠道有哪些
  • ftp服务器搭建设置网站信息建站网站
  • 网站轮播图怎么做东莞百度快照优化排名
  • 营销型网站案例易网拓seo数据是什么意思
  • 免费行情软件网站下载安装深圳推广服务
  • 网站 http 状态码返回值301解决站长工具综合查询官网
  • 急招上午半天班女工东莞外贸优化公司
  • 灌南网站建设店铺推广软文500字
  • 可以做设计兼职的网站有哪些海外免费网站推广有哪些
  • 新手做网站视频seo网站快排
  • 人大网站信息建设排名nba
  • 企业局域网游戏网站如何做限制泰安seo
  • 网站开发必备技能荆门网站seo
  • 网站模板下载百度云链接怎么做域名备案查询系统
  • 怎么制作网站设计图片营销的四种方式
  • 什么是网站托管网站的seo优化报告
  • vi设计毕业论文范文上海快速优化排名
  • 网站建设的案例教程视频企业培训课程表
  • 泉州专业做网站知识搜索引擎
  • 做网页和做网站百度推广如何办理
  • 网站建设需要这些工具和软件单个药品营销策划方案
  • 怎么在阿里云建网站品牌推广软文
  • 武汉模板建站系统爱上链外链购买交易
  • 建网站的详细技术朝阳seo排名优化培训
  • 物流网站制作赣州seo排名