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

中国电子系统建设公司网站做网站视频存储

中国电子系统建设公司网站,做网站视频存储,pc网站开发制作,宁波网站优化体验定义:设计模式指的是在软件开发过程中,经过验证的,用于解决在特定环境下,重复出现的,特定问题的解决方案。创建型设计模式关注对象的创建过程,提供了更灵活、可扩展的对象创建机制。结构型设计模式用于解决…

定义:设计模式指的是在软件开发过程中,经过验证的,用于解决在特定环境下,重复出现的,特定问题的解决方案。创建型设计模式关注对象的创建过程,提供了更灵活、可扩展的对象创建机制。结构型设计模式用于解决对象之间组合成更大结构的问题,以便更好地管理它们之间的关系

前提:具体需求有稳定点也有变化点,希望将来能够修改少量代码就能适应需求的变化

基础:继承、封装、多态

模版方法:

定义:定义了一个算法的骨架,将算法中的某些步骤延迟到子类中实现

人话:算法子流程是固定的,但是子流程的执行顺序可能会发生变化,因此可以使用继承,在继承基类方法的同时实现一些函数,这些函数的子流程执行顺序是不同的。在程序执行的时候通过晚绑定实例化子类。子类要满足里氏替换原则,就是子类可以完美替代父类。demo program:

#include <iostream>
using namespace std;// 开闭
class ZooShow {
public:void Show() {// 如果子表演流程没有超时的话,进行一个中场游戏环节;如果超时,直接进入下一个子表演流程if (Show0())PlayGame();Show1();Show2();Show3();}private:void PlayGame() {cout << "after Show0, then play game" << endl;}bool expired;// 对其他用户关闭,但是子类开放的
protected:virtual bool Show0() {cout << "show0" << endl;if (! expired) {return true;}return false;}virtual void Show2() {cout << "show2" << endl;}virtual void Show1() {}virtual void Show3() {}
};// 框架
// 模板方法模式
class ZooShowEx10 : public ZooShow {
protected:virtual void Show0() {if (! expired) {return true;}return false;}
}class ZooShowEx1 : public ZooShow {
protected:virtual bool Show0() {cout << "ZooShowEx1 show0" << endl;if (! expired) { // 里氏替换return true;}return false;}virtual void Show2(){cout << "show3" << endl;}
};class ZooShowEx2 : public ZooShow {
protected:virtual void Show1(){cout << "show1" << endl;}virtual void Show2(){cout << "show3" << endl;}
};class ZooShowEx3 : public ZooShow {
protected:virtual void Show1(){cout << "show1" << endl;}virtual void Show3(){cout << "show3" << endl;}virtual void Show4() {//}
};
/*
*/
int main () {ZooShow *zs = new ZooShowEx10; // 晚绑定还是早绑定// ZooShow *zs1 = new ZooShowEx1;// ZooShow *zs2 = new ZooShowEx2;zs->Show();return 0;
}

观察者模式:

定义:用于定义对象之间的一对多依赖关系,当一个对象的状态发生改变时,其所有依赖者(观察者)都会收到通知并自动更新。

人话:定义一个控制类,把所有实例化的对象全部存储到这个类的容器(也可以使用其他类型的数据结构)中,需要更新的时候遍历所有对象修改数据。优点是无需修改依赖和被依赖的对象,缺点是观察者过多影响性能。

代码实例:

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
//
class IDisplay {
public:virtual void Show(float temperature) = 0;virtual ~IDisplay() {}
};class DisplayA : public IDisplay {
public:virtual void Show(float temperature) {cout << "DisplayA Show" << endl;}
private:void jianyi();
};class DisplayB : public IDisplay{
public:virtual void Show(float temperature) {cout << "DisplayB Show" << endl;}
};class DisplayC : public IDisplay{
public:virtual void Show(float temperature) {cout << "DisplayC Show" << endl;}
};class DisplayD : public IDisplay{
public:virtual void Show(float temperature) {cout << "DisplayC Show" << endl;}
};class WeatherData {
};// 应对稳定点,抽象
// 应对变化点,扩展(继承和组合)
class DataCenter {
public:void Attach(IDisplay * ob) {//}void Detach(IDisplay * ob) {//}void Notify() {float temper = CalcTemperature();for (auto &ob : obs) {ob->Show(temper);}}// 接口隔离
private:WeatherData * GetWeatherData();float CalcTemperature() {WeatherData * data = GetWeatherData();// ...float temper/* = */;return temper;}std::list<IDisplay*> obs;
};int main() {// 单例模式DataCenter *center = new DataCenter;// ... 某个模块IDisplay *da = new DisplayA();center->Attach(da);// ...IDisplay *db = new DisplayB();center->Attach(db);IDisplay *dc = new DisplayC();center->Attach(dc);center->Notify();//-----center->Detach(db);center->Notify();center->Notify();return 0;
}

 策略模式:

定义:提供一系列可以重用的算法,使得程序在运行时可以方便的切换。

人话:固定的部分抽象成基类,子类继承基类并且重写基类的虚函数,程序调用的时候根据传入的实例化的类来执行函数。是一种比较好的去处if-else的方法。

例子:

class Context {};// 稳定点:抽象去解决它
// 变化点:扩展(继承和组合)去解决它
class ProStategy {
public:virtual double CalcPro(const Context &ctx) = 0;virtual ~ProStategy(); 
};
// cpp
class VAC_Spring : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};class VAC_Spring_v2 : public VAC_Spring {
public:virtual double CalcPro(const Context &ctx){//....}
};class VAC_worker : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};// cpp
class VAC_QiXi : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};
class VAC_QiXi1  : public VAC_QiXi {
public:virtual double CalcPro(const Context &ctx){}
};
// cpp
class VAC_Wuyi : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};
// cpp
class VAC_GuoQing : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};
class VAC_GuoQing2 : public VAC_GuoQing {
public:virtual double CalcPro(const Context &ctx){}
};class VAC_Shengdan : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};// 设计原则:接口隔离原则
// 组合、继承
// 组合基类指针
// 两种方法:1. 采用具体接口选择算法  2. 依赖注入
class Promotion {
public:Promotion(ProStategy *sss = nullptr) : s(sss){}~Promotion(){}void Choose(ProStategy *sss) {// 条件选择if (sss != nullptr) {s = sss;}}double CalcPromotion(const Context &ctx){if (s != nullptr) {return s->CalcPro(ctx);}return 0.0L;}
private:ProStategy *s;
};int main () {Context ctx;ProStategy *s = new VAC_QiXi1();Promotion *p = new Promotion(s);p->Choose(new VAC_GuoQing2());p->CalcPromotion(ctx);return 0;
}

这是一条吃饭博客,由挨踢零声赞助。学C/C++就找挨踢零声,加入挨踢零声,面试不挨踢!

http://www.yayakq.cn/news/218946/

相关文章:

  • wordpress视频发布站主题苏州 中英文网站建设
  • 南昌专业的企业网站开发公司网站开发技术经理职责
  • 做问卷用哪个网站国内重大新闻10条2022
  • 公司如何做网站推广网站后台管理图片水印怎么做
  • 企业官网seo东营网站优化
  • 如何建立营销型网站建设集团网站方案设计
  • 自适应网站怎么做wordpress不锈钢企业
  • 织梦网站专题模板湖南网站建设公司 都来磐石网络
  • 建材网站建设功能方案做网站谁家好
  • 医院网站建设规范专门做画册封面的网站
  • 网站开发要用什么工具软件上海公司牌照价格2023年
  • 阿里云虚拟主机怎么建设网站浙江和海建设集团网站
  • 手机微网站建设如何 建设一个网站
  • 学校门户网站建设必要性本地app制作公司地址
  • 做网站哪些软件门户网站是专一化好还是多元化好
  • 网站国际推广库尔勒西部建设网站
  • 公司做网站的费用的会计分录可信网站认证代理
  • 手机端网站建设步骤心理咨询中心网站模板
  • 做百度网站每年的费用多少钱网站建设属什么费用
  • 七彩建设发展有限公司官方网站wordpress利用视频引流
  • 网站建设制作视频教程磁力屋 最好用
  • 临沂网站建设费用外贸自建站费用
  • seo外包公司网站关键词seo怎么做
  • 景安网站备案查询品牌推广营销
  • 高流量网站开发框架经验一些js特效的网站推荐
  • 深圳做网站(官网)wordpress 页面位置
  • 六盘水遵义网站建设怎么做做电商需要准备什么
  • 万网的成品网站文档分享类网站建设
  • 网站安全检测wordpress 标题重复
  • 站长工具ip地址查询域名展示型网站建设方案