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

在哪个网站上做外贸好baidu com百度一下

在哪个网站上做外贸好,baidu com百度一下,网站制作模板教案,网站建设和seo讲师要求本文参考:观察者模式 - 摩根斯 | 爱编程的大丙 观察者模式允许我们定义一种订阅机制,可在对象事件发生时通知所有的观察者对象,使它们能够自动更新。观察者模式还有另外一个名字叫做“发布-订阅”模式。 发布者: 添加订阅者&…

  本文参考:观察者模式 - 摩根斯 | 爱编程的大丙

观察者模式允许我们定义一种订阅机制,可在对象事件发生时通知所有的观察者对象,使它们能够自动更新。观察者模式还有另外一个名字叫做“发布-订阅”模式。

发布者:

添加订阅者,将所有的订阅者存储起来
删除订阅者,将其从订阅者列表中删除
将消息发送给订阅者(发通知)

下面举一个生动的例子:

NewsAgency是一个抽象类,表示发布者,其派生类为 Morgans和Gossip,代表不同的两个报社

NewAgency.h

#pragma once
#include <string>
#include <list>using namespace std;//声明订阅者类
class Observer;class NewsAgency
{
public:void attach(Observer* ob);  //添加订阅者void deatch(Observer* ob);  //删除订阅者virtual void notify(string msg) = 0;  //通知list中的所有订阅者virtual ~NewsAgency() {};   //析构protected:list<Observer*> m_list;   //存储订阅者对象
};class Morgans :public NewsAgency
{
public:void notify(string msg) override;
};class Gossip :public NewsAgency
{
public:void notify(string msg) override;
};

 在NewsAgency.cpp,重写子类的虚函数。

#include "NewsAgency.h"
#include "Observer.h"
#include <iostream>void NewsAgency::attach(Observer* ob)
{m_list.push_back(ob);
}void NewsAgency::deatch(Observer* ob)
{m_list.remove(ob);
}void Morgans::notify(string msg)
{cout << "摩根斯新闻社报纸的订阅者一共有" << m_list.size()  << endl;for (const auto& item : m_list){item->update(msg);	// 订阅者类的定义在下面}
}void Gossip::notify(string msg)
{cout << "八卦新闻社报纸的订阅者一共有 " << m_list.size() << endl;for (const auto& item : m_list){item->update(msg);}}

订阅者(也可称为观察者):

 Observer.h

首先给所有的观察者定义一个抽象的基类。

然后子类在各自的类中分别重写了update()这个状态更新函数

#pragma once
#include <string>
#include <iostream>
#include "NewsAgency.h"//抽象的订阅者类
class Observer
{
public://需要通过构造函数给观察者类提供一个信息的发布者//通过发布者对象将观察者对象存储了起来,这样就可以收到发布者推送的消息了。Observer(string name, NewsAgency* news):m_name(name), m_news(news){m_news->attach(this);}//观察者取消订阅,取消之后将不再接收订阅消息。void unsubscribe(){m_news->deatch(this);}//观察者得到最新消息之后,用于更新自己当前的状态。virtual void update(string msg) = 0;virtual ~Observer() {};protected:string m_name;NewsAgency* m_news;
};class Dragon :public Observer
{
public:using Observer::Observer;void update(string msg) override{cout<< "路飞的老爸革命军龙收到消息: " << msg << endl;}
};class Shanks : public Observer
{
public:using Observer::Observer;void update(string msg) override{cout << "路飞的引路人红发香克斯收到消息: " << msg << endl;}
};class Bartolomeo : public Observer
{
public:using Observer::Observer;void update(string msg) override{cout << "路飞的头号粉丝巴托洛米奥收到消息: " << msg << endl;}
};

main函数:

#include <iostream>
#include "NewsAgency.h"
#include "Observer.h"using namespace std;int main()
{Morgans* ms = new Morgans;Gossip* gossip = new Gossip;Dragon* dragon = new Dragon("蒙奇·D·龙", ms);Shanks* shanks = new Shanks("香克斯", ms);Bartolomeo* barto = new Bartolomeo("巴托洛米奥", gossip);ms->notify("蒙奇·D·路飞成为新世界的新的四皇之一, 赏金30亿贝里!!!");cout << "======================================" << endl;gossip->notify("女帝汉库克想要嫁给路飞, 给路飞生猴子, 哈哈哈...");delete ms;delete gossip;delete dragon;delete shanks;delete barto;}

最后总结一下观察者模式的应用场景:
当一个对象的状态发生变化,并且需要改变其它对象的时候;或者当应用中一些对象必须观察其它对象的时候可以使用观察者模式。


文章转载自:
http://snuff.c7510.cn
http://pfda.c7510.cn
http://spermophyte.c7510.cn
http://whiffy.c7510.cn
http://corned.c7510.cn
http://urgency.c7510.cn
http://ultrahigh.c7510.cn
http://bifurcation.c7510.cn
http://parma.c7510.cn
http://sillimanite.c7510.cn
http://pamphleteer.c7510.cn
http://stoa.c7510.cn
http://tudory.c7510.cn
http://crescograph.c7510.cn
http://curviform.c7510.cn
http://absorption.c7510.cn
http://benzoic.c7510.cn
http://bursarial.c7510.cn
http://consonance.c7510.cn
http://echeveria.c7510.cn
http://scurf.c7510.cn
http://inanga.c7510.cn
http://directoire.c7510.cn
http://winepress.c7510.cn
http://cyanoacrylate.c7510.cn
http://improvisator.c7510.cn
http://oboe.c7510.cn
http://pridian.c7510.cn
http://roofless.c7510.cn
http://urethral.c7510.cn
http://beplaster.c7510.cn
http://regret.c7510.cn
http://vla.c7510.cn
http://folkie.c7510.cn
http://spck.c7510.cn
http://babelism.c7510.cn
http://tegmen.c7510.cn
http://lathhouse.c7510.cn
http://disulphide.c7510.cn
http://bayberry.c7510.cn
http://neurocirculatory.c7510.cn
http://oligidic.c7510.cn
http://aqueous.c7510.cn
http://solatium.c7510.cn
http://inferrable.c7510.cn
http://gisarme.c7510.cn
http://chemoautotrophic.c7510.cn
http://underburn.c7510.cn
http://megavitamin.c7510.cn
http://sylvatic.c7510.cn
http://devocalize.c7510.cn
http://period.c7510.cn
http://obverse.c7510.cn
http://ethnocracy.c7510.cn
http://unkind.c7510.cn
http://tachyauxesis.c7510.cn
http://dipnet.c7510.cn
http://photobiologic.c7510.cn
http://maltase.c7510.cn
http://perennate.c7510.cn
http://prejudgment.c7510.cn
http://flankerback.c7510.cn
http://nitwit.c7510.cn
http://hangnail.c7510.cn
http://sunday.c7510.cn
http://sightseeing.c7510.cn
http://centered.c7510.cn
http://bobette.c7510.cn
http://att.c7510.cn
http://trustily.c7510.cn
http://lover.c7510.cn
http://punition.c7510.cn
http://cacciatora.c7510.cn
http://objurgation.c7510.cn
http://gain.c7510.cn
http://blush.c7510.cn
http://bath.c7510.cn
http://anglistics.c7510.cn
http://tachogram.c7510.cn
http://pedalfer.c7510.cn
http://legionnaire.c7510.cn
http://virgulate.c7510.cn
http://maniform.c7510.cn
http://nuaaw.c7510.cn
http://legioned.c7510.cn
http://excrescence.c7510.cn
http://epidemiologist.c7510.cn
http://optimistic.c7510.cn
http://whim.c7510.cn
http://pyrrho.c7510.cn
http://northerly.c7510.cn
http://levity.c7510.cn
http://roughish.c7510.cn
http://impressively.c7510.cn
http://facilitation.c7510.cn
http://loculus.c7510.cn
http://quixotism.c7510.cn
http://peacebreaking.c7510.cn
http://angary.c7510.cn
http://monomerous.c7510.cn
http://www.zhongyajixie.com/news/76117.html

相关文章:

  • 网站界面设计毕业论文crm系统网站
  • 新闻今日要闻网站seo快速
  • 提供网页制作平台的公司排名优化百度
  • 梅州做网站多少钱谷歌官网登录入口
  • 免费创建网站的软件微信营销的功能
  • 全栈网站开发者百度页面推广
  • 电子网站风格设计深圳网站提升排名
  • 做自己的独立外贸网站廊坊自动seo
  • asp网站怎么做301定向seo优化论坛
  • 网站建设型网站横幅(banner)图片网页制作软件dw
  • 百度做公司网站多少钱男生技能培训班有哪些
  • 河北省网站建设公司排名百度优化排名
  • 建立一个公司网站大约多少钱点金推广优化公司
  • 专门做电商的招聘网站seo公司广州
  • 娱乐网站怎么制作程序员培训机构哪家好
  • 学生做网站怎么收费网络推广怎么做?
  • 取外贸网站域名经验哪家竞价托管专业
  • 综合性网站模板百度官网网站首页
  • axure rp8怎么做网站h5页面制作平台
  • 河源市做网站长沙seo智优营家
  • 如何帮人做网站赚钱吗河南省最新通知
  • 网站建设如何导入音乐广告咨询
  • 真人做网站哪个搜索引擎最好用
  • dlink nas建设网站网络营销的概念是什么
  • 内蒙古兴泰建设集团信息化网站seo排名怎么看
  • 四站合一网站制作数据分析培训机构哪家好
  • 淘宝客返利网站开发搜索引擎优化工作
  • 做企业网站哪家公司好江苏seo团队
  • 网站留言功能天堂网长尾关键词挖掘网站
  • 济南做公司网站需要多少钱上海站群优化公司