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

wordpress电影网站模板wordpress 颜色选择器

wordpress电影网站模板,wordpress 颜色选择器,工业互联网平台系统,医疗设备网站建设怎么做单例模式 单例模式保证一个类只能创建一个对象#xff0c;并提供全局访问点。通常用于全局共享例如日志、数据库连接池等。 Lazy Initialization 优点#xff1a;需要时才初始化#xff0c;节省空间 缺点#xff1a;线程不安全 class Singleton{ private:static Singlet…单例模式 单例模式保证一个类只能创建一个对象并提供全局访问点。通常用于全局共享例如日志、数据库连接池等。 Lazy Initialization 优点需要时才初始化节省空间 缺点线程不安全 class Singleton{ private:static Singleton* instance;//提供的静态成员Singleton() {}//重写构造函数为私有禁止使用通常方法创建Singleton public://外界只能通过getInstance去获取静态成员从而保证只有一个实例ststic Singleton* getInstance(){if(instance nullptr)instance new Singleton();//可能会有多个线程同时执行这句导致问题return instance;} } Eager Initialization 优点线程安全 缺点不管用不用都会初始化占空间 class Singleton{ private:static Singleton* instance;Singleton(){} public:static Singleton* getInstance(){return instance;} }Singleton* Singleton::instance new Singleton(); Double-Checked Locking 优点延迟加载、线程安全 缺点没有 #include mutexclass Singleton{ private:static volatile Singleton* instance;static std::mutex mtx;Singleton(){} public:static volatile Singleton* getInstance(){if(instance nullptr){std::lock_guardstd::mutex lock(mtx);if(instance nullptr){ //double-checked lockinginstance new Singleton();}}return instance; } };volatile Singleton* Singleton::instance nullptr; std::mutex Singleton::mtx; 代理模式 我要租房我不去租找了个中介去租。 class Person{ public:virtual void rentHouse() 0;//纯虚函数 }class I : public Person{ public:void rentHouse(){std::cout I want to rent a house.endl;} };class Intermediary : public Person{ public: Intermediary(Person * person) : m_person(person) {}void rentHouse(){m_person-rentHouse();std::cout Iam Intermediary.endl;} private:Person *m_person; };void testDalegate() {Person *i new I();Person *intermediary new Intermediary(i);intermediary-rentHouse(); } 简单工厂模式 简单工厂模式是一种实例化对象的方式只要我们输入的实例化信息就可以通过工厂方式实例化相应的实例化对象。 class TelPhone{ public:enum PhoneType{Mi, Oppo, Huawei};virtual void setName(std::string name) 0;virtual void setPrice(double price) 0;virtual double getPrice() 0; protected:std::string name;double price; };class MiPhone : public TelPhone{ public: Miphone(){setname(mi15);setprice(1234)}std::string getName(){return TelPhone::name;}std::double getPrice(){return TelPhone::Price;}void setName(std::string name){TelPhone::name name;}void setPrice(double price){TelPhone::price price;}}; class OppoPhone : public TelPhone{//... }; class HuaWeiPhone : public TelPhone{//... };class TelPhoneFactory{ public://生产手机static TelPhone* productTelPhone(TelPhone::PhoneType phoneType){TelPhone *telp nullptr;swith(phoneType){case TelPhone::Mi:telp new Miphone();break;case TelPhone::Oppo:telp new Oppophone();break;case TelPhone::Huawei:telp new Huaweiphone();break;default:break;}return telp;} };void testFactory(){TelPhone *telp TelPhoneFactory::productTelPhone(TelPhone::Mi);if(telp ! nullptr){std::couttelp-getName() std::endl;std::couttelp-getPrice() std::endl;} } 观察者模式 又叫发布-订阅模式定义对象间一对多的关系当一个对象状态发生变化时其所有依赖者都会收到通知 原型模式 用一个以及创建的实例作为原型通过复制该原型对象来创建一个和原型相同或者相似的对象。类似原件和复印件的关系。 策略模式 定义一系列算法把他们一个个封装起来并且使他们可以相互替换。通过策略模式可以动态的选择、配置和切换算法而无需修改客户端代码。 #includeiostreamenum StrategyType{E_StrategyNight,E_StraegyWeekend, }; class Strategy{ public:virtual void algorithm() 0;virtual ~Strategy(){} };class StrategyNight : public Strategy{ public:void algorithm(){std::cout 晚上加班计算方法std::endl;}virtual ~StrategyNight(){} };class StraegyWeekend : public Strategy{ public:void algorithm(){std::cout周末加班std::endl;}virtual ~StraegyWeekend(){} };class Context{ public:Context(StrategyType strategyType){switch (strategyType){case E_StrategyNight:pStrategy new StrategyNight();break;case E_StraegyWeekend:pStrategy new StraegyWeekend();break;default:break;}}~Context(){if(pStrategy)delete pStrategy;}void overtimePay(){if(pStrategy){pStrategy-algorithm();}} private:Strategy* pStrategy; };int main(){Context *pcont new Context(E_StraegyWeekend);pcont-overtimePay();if(pcont)delete pcont;return 0; } 中介者模式 定义一个中介对象来封装一系列对象之间的交互使得原有对象之间的耦合松散且可以独立地改变他们之间的交互。 #includeiostream #includevector #includestring using namespace std;class Employee{ private:string m_strName;string m_strContent; public:Employee(string strName) : m_strName(strName){}void setName(string strName){m_strName strName;}string getName(){return m_strName;}void setContent(string content){m_strContent content;}string getContent(){if(m_strContent.empty())return 收到;return m_strContent;}virtual void talk() 0; };class Boss : public Employee{ public:Boss(string str) :Employee(str){}void talk(){cout getName() says: getContent()endl;} };class Manager : public Employee{ public:Manager(string str) :Employee(str){}void talk(){cout getName() says: getContent()endl;} }; class Securtity: public Employee{ public:Securtity(string str) :Employee(str){}void talk(){cout getName() says: getContent()endl;} };class Mediator{ protected:vectorEmployee* vec_emp;public:void addEmployee(Employee* emp){vec_emp.push_back(emp);}virtual void notify(Employee* emp) 0; };class HolidaysMediator : public Mediator{ public:void notify(Employee* emp){ emp-talk();for(int i 0; i vec_emp.size(); i){if(emp ! vec_emp[i]){vec_emp[i]-talk();}}} };int main(){HolidaysMediator holidaysMediator;Boss* boss new Boss(老板);Manager* manager new Manager(经理);Securtity* securtity new Securtity(保安);holidaysMediator.addEmployee(boss);holidaysMediator.addEmployee(manager);holidaysMediator.addEmployee(securtity);boss-setContent(明天放假);holidaysMediator.notify(boss);return 0;} 责任链模式 用来处理相关事务的一条执行链执行链上有多个节点每个节点都有机会处理请求事务如果某个节点处理完就可以根据实际业务需求传递给下一个节点继续处理或者返回处理完毕。 #includeiostream using namespace std;class Logger{ public:enum LEVEL {DEBUG,INFO,WARN,ERROR };LEVEL m_level LEVEL::DEBUG;Logger(){ }virtual ~Logger(){}void logMessage(LEVEL level, string message){if(m_level level){write(message);}if(m_nextLogger ! NULL){m_nextLogger-logMessage(level, message);}}void setNextLogger(Logger* nextLogger){m_nextLogger nextLogger;} protected:virtual void write(string logger){};Logger* m_nextLogger; };class DebugLogger : public Logger{ public:DebugLogger(LEVEL level){m_level level;}void write(string logger){cout Debug Logger: m_level , message:loggerendl;} }; class ErrorLogger : public Logger{ public:ErrorLogger(LEVEL level){m_level level;}void write(string logger){cout Error Logger: m_level , message:loggerendl;} };class InfoLogger : public Logger{ public:InfoLogger(LEVEL level){m_level level;}void write(string logger){cout Info Logger: m_level , message:loggerendl;} };class WarnLogger : public Logger{ public:WarnLogger(LEVEL level){m_level level;}void write(string logger){cout Warn Logger: m_level , message:loggerendl;} };class Client{ public:Client(){}~Client(){}void test(){Logger *logger getChainOfLoggers();logger-logMessage(Logger::DEBUG, this is debug);cout --------------endl;logger-logMessage(Logger::DEBUG, this is info);cout --------------endl;logger-logMessage(Logger::DEBUG, this is warn);cout --------------endl;logger-logMessage(Logger::DEBUG, this is error);} private:Logger* getChainOfLoggers(){Logger *debug new DebugLogger(Logger::DEBUG);Logger *info new InfoLogger(Logger::INFO);Logger *warn new WarnLogger(Logger::WARN);Logger *error new ErrorLogger(Logger::ERROR);error-setNextLogger(warn);warn-setNextLogger(info);info-setNextLogger(debug);return error;} };int main(){Client client;client.test();return 0; }
http://www.dnsts.com.cn/news/203542.html

相关文章:

  • 电子网站大全盘锦网站建设价位
  • 网站建设开票开什么内容微信电商平台
  • 开县集团网站建设网站建设存在的问题及建议
  • 在线编写html网页代码站内优化包括哪些
  • 国外的ps网站上海网页设计培训机构
  • 什么是网站链接优化wordpress固定链接域名
  • 银川企业网站设计制作抖音优化
  • 百度 网站建设网络广告营销方案
  • 恶意镜像网站程序企业为什么需要管理
  • 一个网站有多少网页室内装修设计在哪里学
  • 河北廊坊建设银行网站贵州建设厅文件网站首页
  • 网站已有备案了 现在换空间商还用备案么网站开发的心得体会
  • 专做老酒的网站做推广效果哪个网站好
  • 小说网站怎么做防采集房屋租赁系统网站开发
  • 天津企业网站建设哪家好芜湖app开发
  • 太仓高端网站制作中国十大电商公司
  • asp网站表格代码顺德电子画册网站建设
  • 做网站昆山小程序定制开发中心
  • 南京 外贸网站建设禁止拿我们的网站做宣传
  • 教育培训网页设计南宁网站seo外包
  • 深圳筑造建设有限公司网站国内优秀网页网站设计
  • 永久免费网站推荐江苏永坤建设有限公司网站
  • 专门做母婴的网站易语言网站建设
  • 个人做网站做什么样的话打折网站建设教程下载
  • 网站更新问题类似稿定设计的网站
  • 易迈互联网站建设怎么样河北邯郸有几个区县
  • 做商城网站服务器配置怎么选择徐州seo公司
  • 郑州做网站元辰什么是网站空间
  • 做影视网站存储视频会侵权吗大学生为什么不去中建
  • 做网站推广收入好吗权重较高网站