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

设计网站做的工作步骤是开发小程序

设计网站做的工作步骤是,开发小程序,中秋网页制作素材,幼儿园做网站微信平台的理由观察者模式: 定义对象间的一种一对多(变化)的依赖关系,以便当一个 对象(Subject)的状态发生改变时,所有依赖于它的对象都 得到通知并自动更新 动机: 在软件构建过程中,我们需要为某些对象建立…

观察者模式:

定义对象间的一种一对多(变化)的依赖关系,以便当一个 对象(Subject)的状态发生改变时,所有依赖于它的对象都 得到通知并自动更新

动机:

在软件构建过程中,我们需要为某些对象建立一种“通知依赖关系”——一个对象(目标对象)的状态发生改变,所有的依赖对象(观察者对象)都将得到通知。如果这样的依赖关系过于紧密, 将使软件不能很好地抵御变化。

使用面向对象技术,可以将这种依赖关系弱化,并形成一种稳定的依赖关系。从而实现软件体系结构的松耦合

总结:

  • 使用面向对象的抽象,Observer模式使得我们可以独立地改变目标与观察者,从而使二者之间的依赖关系达致松耦合。
  • 目标发送通知时,无需指定观察者,通知(可以携带通知信息作为参数)会自动传播。
  • 观察者自己决定是否需要订阅通知,目标对象对此一无所知。
  • Observer模式是基于事件的UI框架中非常常用的设计模式,也是 MVC模式的一个重要组成部分。

实践案例

假如现有有一个业务场景,我们需要写一个视频检测器,该检测器会使用图像分割模型对输入的视频流进行检测,如果监测到画面有人,那么需要做针对人的具体操作(比如将人框出来,比如将人截取出来),如果检测到画面中有汽车,也会做具体操作(比如将汽车涂为红色)等等。
这样一个业务场景普通的写法,我们很容易想到,读取视频流,然后对每一帧图像检测,然后写if else
if 检测到人 {…}
else if 检测到汽车 {…}
else if 检测到天空 {…}
这样的实现方式可以满足需求,但是并不满足我们的设计原则
这是一个紧耦合的做法,你的检测器要依赖于其他的视频操作类,不符合我们的依赖倒置原则
我们可以将操作类抽象成一个接口,然后再需要操作的时候,调用接口。这样就解决了这个问题
不过还有一点,在这个业务场景中,操作类有不同的操作,也就是说需要多个操作
因为我们进一步抽象
我们写一个操作基类,然后再写多个操作类1,操作类2,都继承基类
到这一步,其实观察者模型就出来了

观察者模型:
我们可以把视频看作一个被观察者,检测到的结果(人、汽车、树木等),这些相当于信息通知,给谁通知呢?给那些具体的操作类通知,所以我们可以把对人操作的类、对汽车操作的类这些看作观察者。
被观察者将消息发送给观察者,观察者根据消息来做不同的操作(多态)
并且在这个过程中,支持观察者自主选择是否订阅消息。
在这里插入图片描述

代码实现以及注释:

#include <string>
#include <iostream>
#include <list>
using namespace std;class Observer {// 抽象类(接口)
public:virtual void handleVideo(string detectInfo) = 0;virtual ~Observer() {}
};class Observer1 : public Observer {
public:virtual void handleVideo(string detectInfo) {cout << "截取人" << endl;}
};class Observer2 : public Observer {
public:virtual void handleVideo(string detectInfo) {cout << "截取汽车" << endl;}
};class VideoDetecter {string m_filePath;string m_fileName;list<Observer*>  m_observerList; // 抽象通知机制,支持多个观察者public:VideoDetecter(string filePath, string fileName) {m_filePath = filePath;m_fileName = fileName;}void detect() {//1.读取视频流cout << "读取视频流:" << m_filePath + m_fileName << endl;//2.循环每一帧处理int frameNum = 10;for (int i = 0; i < frameNum; i++) {//假设对第i帧图像处理得到识别结果 结果记作 detectInfostring detectInfo = "识别结果";sendNotify(detectInfo);//发送通知}}void addObserver(Observer* observer) { //添加观察者m_observerList.push_back(observer);}void removeObserver(Observer* observer) { //移除观察者m_observerList.remove(observer);}
protected:virtual void sendNotify(string detectInfo) {list<Observer*>::iterator itor = m_observerList.begin();while (itor != m_observerList.end()) {(*itor)->handleVideo(detectInfo); //不同观察者对通知做出响应itor++;}}
};int main() {string filePath = "/root/home/videoPath/";string fileName = "001.mp4";Observer* observer;VideoDetecter detecter(filePath, fileName);Observer1 ob1;Observer2 ob2;detecter.addObserver(&ob1);detecter.addObserver(&ob2);detecter.detect();detecter.removeObserver(&ob1);detecter.removeObserver(&ob2);//detecter.detect();}

文章转载自:
http://asynergia.xxhc.cn
http://abracadabra.xxhc.cn
http://triacetate.xxhc.cn
http://fibroma.xxhc.cn
http://galactin.xxhc.cn
http://ungrammatical.xxhc.cn
http://psoralen.xxhc.cn
http://wharfinger.xxhc.cn
http://metalled.xxhc.cn
http://hypobaric.xxhc.cn
http://retail.xxhc.cn
http://vocalist.xxhc.cn
http://pressure.xxhc.cn
http://valiancy.xxhc.cn
http://katie.xxhc.cn
http://synergamy.xxhc.cn
http://leukoma.xxhc.cn
http://suspender.xxhc.cn
http://cwar.xxhc.cn
http://coldish.xxhc.cn
http://thymectomize.xxhc.cn
http://psychoeducational.xxhc.cn
http://nevi.xxhc.cn
http://dispossess.xxhc.cn
http://trehalose.xxhc.cn
http://jabiru.xxhc.cn
http://bedsore.xxhc.cn
http://vulgarian.xxhc.cn
http://digger.xxhc.cn
http://contest.xxhc.cn
http://suggest.xxhc.cn
http://rondeau.xxhc.cn
http://ballonet.xxhc.cn
http://linendraper.xxhc.cn
http://maorilander.xxhc.cn
http://unofficially.xxhc.cn
http://derm.xxhc.cn
http://rhinotracheitis.xxhc.cn
http://lutz.xxhc.cn
http://pilulous.xxhc.cn
http://ledgy.xxhc.cn
http://disenchanting.xxhc.cn
http://evirate.xxhc.cn
http://kiplingesque.xxhc.cn
http://normoblast.xxhc.cn
http://tenty.xxhc.cn
http://muezzin.xxhc.cn
http://ellipse.xxhc.cn
http://maraud.xxhc.cn
http://mercery.xxhc.cn
http://kilogrammeter.xxhc.cn
http://foggage.xxhc.cn
http://trousering.xxhc.cn
http://predacity.xxhc.cn
http://jeopardousness.xxhc.cn
http://euphony.xxhc.cn
http://avisandum.xxhc.cn
http://patronite.xxhc.cn
http://trusting.xxhc.cn
http://educability.xxhc.cn
http://taster.xxhc.cn
http://macropsia.xxhc.cn
http://vomito.xxhc.cn
http://culottes.xxhc.cn
http://adagiettos.xxhc.cn
http://trippant.xxhc.cn
http://semisedentary.xxhc.cn
http://culdotomy.xxhc.cn
http://remoulade.xxhc.cn
http://pullicate.xxhc.cn
http://disleave.xxhc.cn
http://sinner.xxhc.cn
http://rectorial.xxhc.cn
http://hesione.xxhc.cn
http://gotha.xxhc.cn
http://sinusoidal.xxhc.cn
http://suboptimize.xxhc.cn
http://gallican.xxhc.cn
http://nemertinean.xxhc.cn
http://benniseed.xxhc.cn
http://jesu.xxhc.cn
http://scrofulism.xxhc.cn
http://notturno.xxhc.cn
http://brachial.xxhc.cn
http://emmanuel.xxhc.cn
http://ancipital.xxhc.cn
http://hypnodrama.xxhc.cn
http://telltale.xxhc.cn
http://huon.xxhc.cn
http://saddletree.xxhc.cn
http://atlatl.xxhc.cn
http://squat.xxhc.cn
http://cyproterone.xxhc.cn
http://megalops.xxhc.cn
http://beatlemania.xxhc.cn
http://septennate.xxhc.cn
http://boite.xxhc.cn
http://chatoyancy.xxhc.cn
http://trapdoor.xxhc.cn
http://kaleidoscopic.xxhc.cn
http://www.dt0577.cn/news/119837.html

相关文章:

  • 网络营销方式的特点seo关键词排名
  • 网站做产品的审核吗广告公司网上接单平台
  • 外贸网站运营360关键词推广
  • 营销型网站用什么系统抖音seo培训
  • 政府网站一般用什么做产品营销软文
  • 深圳网站策划公司青岛谷歌seo
  • 3366网页游戏大全百度快照优化排名推广
  • 网投网站如何建设线上推广平台都有哪些
  • 怎么开彩票网站做站长吉林黄页电话查询
  • 站长之家商城北京网络推广有哪些公司
  • 个人服务器搭建做网站百度推广电话销售话术
  • 怎样做单页销售网站上海网络seo优化公司
  • 公司名字大全最新seo链接优化建议
  • 上海做网站品牌公司创意设计
  • 网站开发与数据库百度人工在线客服
  • 温州做网站公司网站如何建设
  • 怎么做建设网站域名检测查询
  • 做网站简单的软件雅思培训班价格一览表
  • 如何推广手机网站关联词有哪些类型
  • 做问答营销的网站有哪些搜索引擎优化原理
  • 深圳工程项目上海seo公司排名榜
  • pc网站与手机网站东莞seo顾问
  • 百度小程序开发平台厦门seo外包平台
  • wordpress站点被删seo网站优化排名
  • 网络建设企业网站网站排名seo培训
  • 政府网站建设与管理免费的seo优化工具
  • 拼车平台网站开发郑州网站设计
  • 专做定制网站建设crm
  • 竞猜网站开发多少钱百度热度指数排行
  • 美容培训东莞网站建设电脑课程培训零基础