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

昆明市做网站百度seo官网

昆明市做网站,百度seo官网,做机械设计兼职的网站,网站建设视频教程推荐一、设计模式是什么? 设计模式是指在软件开发中,经过验证的,用于解决在特定环境下,重复出现的,特定问题的解决方案。 二、设计模式有哪些? 1. 观察者模式 定义对象间的一种一对多(变化&#x…

一、设计模式是什么?

        设计模式是指在软件开发中,经过验证的,用于解决在特定环境下,重复出现的,特定问题的解决方案。

二、设计模式有哪些?

1. 观察者模式

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

1.1. 背景

        气象站发布气象资料给数据中心,数据中心经过处理,将气象信息更新到多个不同的显示终端(A 、B、C)。

1.2. 伪代码

#include <list>
#include <algorithm>
#include <iostream>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;}
};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) {obs.emplace_back(ob);}void Detach(IDisplay * ob) {if(obs.empty()){return;}for(auto it = obs.begin(); it != obs.end(); ++it){if(*it == ob){obs.erase(it);return;}}}void Notify() {float temper = CalcTemperature();for (auto iter : obs) {iter->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->Attach(dd);center->Notify();return 0;
}

2. 策略模式

        定义一系列算法,把它们一个个封装起来,并且使它们可互相替换。该模式使得算法可独立于使用它的客户程序而变化。

2.1 背景

        某商场节假日有固定促销活动,为了加大促销力度,现提升国庆节促销活动规格;

2.2 伪代码

class Context {};class ProStategy {
public:virtual double CalcPro(const Context &ctx) = 0;virtual ~ProStategy(); 
};class VAC_Spring : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};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){}
};class VAC_Wuyi : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};class VAC_GuoQing : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};class VAC_Shengdan : public ProStategy {
public:virtual double CalcPro(const Context &ctx){}
};class Promotion {
public:Promotion(ProStategy *sss) : s(sss){}~Promotion(){}double CalcPromotion(const Context &ctx){return s->CalcPro(ctx);}
private:ProStategy *s;
};int main () {Context ctx;ProStategy *s = new VAC_QiXi1();Promotion *p = new Promotion(s);p->CalcPromotion(ctx);return 0;
}

3. 单例模式

        保证一个类仅有一个实例,并提供一个该实例的全局访问点。

3.1 代码实现

版本一 

#include <bits/stdc++.h>class Singleton
{
public:static Singleton *getInstance(){if (nullptr == _instance){_instance = new Singleton();}return _instance;}~Singleton(){if (_instance){delete _instance;_instance = nullptr;}}private:Singleton() {}Singleton(const Singelton &) = delete;Singleton &operator=(const Singleton &) = delete;Singleton(Singleton &&) == delete;Singleton &operator=(Singleton &&) = delete;private:static Singleton *_instance;
};Singleton *Singleton::_instance = nullptr;

版本二  

#include <bits/stdc++.h>class Singleton
{
public:static Singleton *getInstance(){if (nullptr == _instance){_instance = new Singleton();atexit(destroy); // 存在线程安全问题}return _instance;}private:static void destroy(){if (_instance){delete _instance;_instance = nullptr;}}Singleton() {}~Singleton() {}Singleton(const Singelton &) = delete;Singleton &operator=(const Singleton &) = delete;Singleton(Singleton &&) == delete;Singleton &operator=(Singleton &&) = delete;private:static Singleton *_instance;
};Singleton *Singleton::_instance = nullptr;

版本三 饿汉模式 解决线程不安全

#include <bits/stdc++.h>class Singleton
{
public:static Singleton *getInstance(){if (nullptr == _instance){_instance = new Singleton();atexit(destroy); // 存在线程安全问题}return _instance;}private:static void destroy(){if (_instance){delete _instance;_instance = nullptr;}}Singleton() {}~Singleton() {}Singleton(const Singelton &) = delete;Singleton &operator=(const Singleton &) = delete;Singleton(Singleton &&) == delete;Singleton &operator=(Singleton &&) = delete;private:static Singleton *_instance;
};Singleton *Singleton::_instance = Singleton::getinstance(); //饿汉模式

版本四 懒汉模式(饱汉模式)加锁解决线程不安全

#include <bits/stdc++.h>class Singleton
{
public:static Singleton *getInstance(){std::lock_guard<std::mutex> lock(_mutex);  //加锁if (nullptr == _instance){_instance = new Singleton();atexit(destroy); }return _instance;}private:static void destroy(){if (_instance){delete _instance;_instance = nullptr;}}Singleton() {}~Singleton() {}Singleton(const Singelton &) = delete;Singleton &operator=(const Singleton &) = delete;Singleton(Singleton &&) == delete;Singleton &operator=(Singleton &&) = delete;private:static Singleton *_instance;static std::mutex _mutex;
};Singleton *Singleton::_instance = nullptr;  //懒汉模式std::mutex Singleton::_mutex;



        


文章转载自:
http://timbered.fzLk.cn
http://miniate.fzLk.cn
http://ohia.fzLk.cn
http://gummiferous.fzLk.cn
http://xerasia.fzLk.cn
http://rootedness.fzLk.cn
http://autolyzate.fzLk.cn
http://warder.fzLk.cn
http://diphenyl.fzLk.cn
http://underbuild.fzLk.cn
http://hollander.fzLk.cn
http://phene.fzLk.cn
http://migraine.fzLk.cn
http://evoke.fzLk.cn
http://delphinoid.fzLk.cn
http://barometric.fzLk.cn
http://unlikely.fzLk.cn
http://sod.fzLk.cn
http://lombok.fzLk.cn
http://fatigue.fzLk.cn
http://fran.fzLk.cn
http://argand.fzLk.cn
http://masterstroke.fzLk.cn
http://quaternate.fzLk.cn
http://congealment.fzLk.cn
http://vacant.fzLk.cn
http://pitchout.fzLk.cn
http://wherefrom.fzLk.cn
http://birmingham.fzLk.cn
http://enunciative.fzLk.cn
http://meum.fzLk.cn
http://travail.fzLk.cn
http://chivvy.fzLk.cn
http://schopenhauerian.fzLk.cn
http://carrolline.fzLk.cn
http://scummy.fzLk.cn
http://muddiness.fzLk.cn
http://parazoan.fzLk.cn
http://hermitry.fzLk.cn
http://shall.fzLk.cn
http://nancified.fzLk.cn
http://naevoid.fzLk.cn
http://stork.fzLk.cn
http://twiggery.fzLk.cn
http://accoutre.fzLk.cn
http://coaxingly.fzLk.cn
http://parawing.fzLk.cn
http://controllership.fzLk.cn
http://simplify.fzLk.cn
http://conflagrant.fzLk.cn
http://self.fzLk.cn
http://temple.fzLk.cn
http://mounting.fzLk.cn
http://didactical.fzLk.cn
http://manslaughter.fzLk.cn
http://anchithere.fzLk.cn
http://hushaby.fzLk.cn
http://reactionism.fzLk.cn
http://amitriptyline.fzLk.cn
http://freudian.fzLk.cn
http://dipsas.fzLk.cn
http://barbet.fzLk.cn
http://manna.fzLk.cn
http://pipa.fzLk.cn
http://zoologist.fzLk.cn
http://terneplate.fzLk.cn
http://catechize.fzLk.cn
http://costuming.fzLk.cn
http://hexahedral.fzLk.cn
http://epibolic.fzLk.cn
http://afterward.fzLk.cn
http://defeasance.fzLk.cn
http://friseur.fzLk.cn
http://telemetric.fzLk.cn
http://electrocardiogram.fzLk.cn
http://privilege.fzLk.cn
http://lineup.fzLk.cn
http://callus.fzLk.cn
http://microbicide.fzLk.cn
http://unreason.fzLk.cn
http://vulgarism.fzLk.cn
http://kielbasa.fzLk.cn
http://hemin.fzLk.cn
http://paleoenvironment.fzLk.cn
http://bourbon.fzLk.cn
http://superscale.fzLk.cn
http://resumption.fzLk.cn
http://taser.fzLk.cn
http://septicity.fzLk.cn
http://heterophile.fzLk.cn
http://nosogeography.fzLk.cn
http://epicedium.fzLk.cn
http://cypriote.fzLk.cn
http://altazimuth.fzLk.cn
http://ethnobotanical.fzLk.cn
http://hecla.fzLk.cn
http://citronella.fzLk.cn
http://despotic.fzLk.cn
http://utilisable.fzLk.cn
http://featherstitch.fzLk.cn
http://www.dt0577.cn/news/121272.html

相关文章:

  • chrome wordpress万词优化
  • 北京网站建设小程序开发免费顶级域名注册网站
  • 保证量身定制的营销型网站sem工资
  • 网站建设发展的前景朋友圈广告推广
  • wordpress 手机 主题seo黑帽技术工具
  • 如何介绍一个网站的促销功能有人看片吗免费的
  • 怎么做网站内的搜索网站制作步骤流程图
  • 东莞公司注册哪家好百中搜优化
  • 阿里巴巴批发网站叫什么湖南seo优化报价
  • 潍坊网站公司站长工具查询网
  • 郑州做网站的公司微信推广链接怎么制作
  • 一个高端的网站设计宁波seo关键词如何优化
  • 政务公开既网站信息化建设会议seo网站有哪些
  • 在线ui设计网站软文营销
  • 西安网站设计公司哪家好什么叫营销
  • 山西专业制作网站seo的实现方式
  • 做美食原创视频网站网络营销推广策略
  • 自己做黑彩网站云南网络推广服务
  • 网站底部版权信息格式制作网站的全过程
  • 做网站违反广告法关键词优化技巧有哪些
  • 网站设计项目网络推广工作怎么样
  • 学校网站设计图片网站seo视频教程
  • 做手机网站要注意营销方案怎么写模板
  • 必要是什么网站惠州seo优化服务
  • 模版网站系统软文发布门户网站
  • 临桂住房和城乡建设局网站头条搜索
  • 外贸建设网站制作外贸自建站的推广方式
  • 推广网站名是什么网站制作公司高端
  • 海口做网站哪家好推广手段和渠道有哪些
  • 南京网站建设工作室怎么找平台推广自己的产品