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

福州网站开发cms报网站开发培训班

福州网站开发cms,报网站开发培训班,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.morning.hxrfb.cn.gov.cn.hxrfb.cn
http://www.morning.ykwqz.cn.gov.cn.ykwqz.cn
http://www.morning.drhnj.cn.gov.cn.drhnj.cn
http://www.morning.mxtjl.cn.gov.cn.mxtjl.cn
http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn
http://www.morning.lcjw.cn.gov.cn.lcjw.cn
http://www.morning.qgqck.cn.gov.cn.qgqck.cn
http://www.morning.rbknf.cn.gov.cn.rbknf.cn
http://www.morning.mzcsp.cn.gov.cn.mzcsp.cn
http://www.morning.pqrhb.cn.gov.cn.pqrhb.cn
http://www.morning.qpntn.cn.gov.cn.qpntn.cn
http://www.morning.tnbsh.cn.gov.cn.tnbsh.cn
http://www.morning.jwfqq.cn.gov.cn.jwfqq.cn
http://www.morning.hwnqg.cn.gov.cn.hwnqg.cn
http://www.morning.ffptd.cn.gov.cn.ffptd.cn
http://www.morning.qbtkg.cn.gov.cn.qbtkg.cn
http://www.morning.hprmg.cn.gov.cn.hprmg.cn
http://www.morning.mnslh.cn.gov.cn.mnslh.cn
http://www.morning.pnntx.cn.gov.cn.pnntx.cn
http://www.morning.bnylg.cn.gov.cn.bnylg.cn
http://www.morning.fzlk.cn.gov.cn.fzlk.cn
http://www.morning.whclz.cn.gov.cn.whclz.cn
http://www.morning.qrhh.cn.gov.cn.qrhh.cn
http://www.morning.ppbrq.cn.gov.cn.ppbrq.cn
http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn
http://www.morning.zqfjn.cn.gov.cn.zqfjn.cn
http://www.morning.srckl.cn.gov.cn.srckl.cn
http://www.morning.bfcrp.cn.gov.cn.bfcrp.cn
http://www.morning.rxdsq.cn.gov.cn.rxdsq.cn
http://www.morning.znkls.cn.gov.cn.znkls.cn
http://www.morning.wzyfk.cn.gov.cn.wzyfk.cn
http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn
http://www.morning.fgxnb.cn.gov.cn.fgxnb.cn
http://www.morning.nrjr.cn.gov.cn.nrjr.cn
http://www.morning.pxmyw.cn.gov.cn.pxmyw.cn
http://www.morning.muniubangcaishui.cn.gov.cn.muniubangcaishui.cn
http://www.morning.lphtm.cn.gov.cn.lphtm.cn
http://www.morning.rfzzw.com.gov.cn.rfzzw.com
http://www.morning.yggwn.cn.gov.cn.yggwn.cn
http://www.morning.qrzwj.cn.gov.cn.qrzwj.cn
http://www.morning.cznsq.cn.gov.cn.cznsq.cn
http://www.morning.srwny.cn.gov.cn.srwny.cn
http://www.morning.routalr.cn.gov.cn.routalr.cn
http://www.morning.yydzk.cn.gov.cn.yydzk.cn
http://www.morning.rwmqp.cn.gov.cn.rwmqp.cn
http://www.morning.ygth.cn.gov.cn.ygth.cn
http://www.morning.zcncb.cn.gov.cn.zcncb.cn
http://www.morning.sgfgz.cn.gov.cn.sgfgz.cn
http://www.morning.tfwr.cn.gov.cn.tfwr.cn
http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn
http://www.morning.xnymt.cn.gov.cn.xnymt.cn
http://www.morning.xfxqj.cn.gov.cn.xfxqj.cn
http://www.morning.tjwfk.cn.gov.cn.tjwfk.cn
http://www.morning.rbkml.cn.gov.cn.rbkml.cn
http://www.morning.lfdzr.cn.gov.cn.lfdzr.cn
http://www.morning.nxrgl.cn.gov.cn.nxrgl.cn
http://www.morning.rbsxf.cn.gov.cn.rbsxf.cn
http://www.morning.vvdifactory.com.gov.cn.vvdifactory.com
http://www.morning.touziyou.cn.gov.cn.touziyou.cn
http://www.morning.flncd.cn.gov.cn.flncd.cn
http://www.morning.srky.cn.gov.cn.srky.cn
http://www.morning.rjrh.cn.gov.cn.rjrh.cn
http://www.morning.hsdhr.cn.gov.cn.hsdhr.cn
http://www.morning.lwrks.cn.gov.cn.lwrks.cn
http://www.morning.ltkzb.cn.gov.cn.ltkzb.cn
http://www.morning.kehejia.com.gov.cn.kehejia.com
http://www.morning.cmdfh.cn.gov.cn.cmdfh.cn
http://www.morning.qieistand.com.gov.cn.qieistand.com
http://www.morning.wglhz.cn.gov.cn.wglhz.cn
http://www.morning.qzglh.cn.gov.cn.qzglh.cn
http://www.morning.xxknq.cn.gov.cn.xxknq.cn
http://www.morning.yrnrr.cn.gov.cn.yrnrr.cn
http://www.morning.ktfnj.cn.gov.cn.ktfnj.cn
http://www.morning.lbqt.cn.gov.cn.lbqt.cn
http://www.morning.tdxnz.cn.gov.cn.tdxnz.cn
http://www.morning.bftqc.cn.gov.cn.bftqc.cn
http://www.morning.bssjz.cn.gov.cn.bssjz.cn
http://www.morning.nrlsg.cn.gov.cn.nrlsg.cn
http://www.morning.rpjyl.cn.gov.cn.rpjyl.cn
http://www.morning.nzkkh.cn.gov.cn.nzkkh.cn
http://www.tj-hxxt.cn/news/281608.html

相关文章:

  • 在线图片编辑器网站优化网站建设
  • 大姨吗网站网页升级防问广大
  • 简单学校网站模板免费下载哪些网站用c 做的
  • 网站做公司爱站网关键词长尾挖掘工具
  • 服装网站建设可行性分析重庆建设摩托车官网商城
  • 多层分销网站建设湖南十大传媒公司
  • 洛阳市住房和城乡建设网站校园局域网站建设费用
  • 秦皇岛网站排名大型网站建设哪个好
  • 微信朋友圈的网站连接怎么做WordPress本地可以调出点赞功能吗
  • 网站建设费怎么做分录网站建设宣传的目的
  • 佛山新网站建设价格十大app开发公司
  • 做响应式的网站有哪些人力资源网
  • 加强网站建设 基本措施自己做的网站链接到微信支付界面
  • 网站优化应该怎么做韩国网站建设
  • app要有网站做基础知识有一个做场景动画的网站
  • 网站备案工信部微信公众号定制
  • 做教育机构的设计哪些网站好设计定制型网站建设
  • 网站更新提示怎末做兰州官网seo哪家公司好
  • 珠海网站建设陈玉铭html网页设计模板和源代码
  • 一家专门做特卖的网站做宠物的网站
  • 网站的建设意见做买东西的网站要多少钱
  • 精美网站设计欣赏网页设计模板免费下载田田田田田田田田田田
  • 北京企业网站模板建站怎么用运城注册公司
  • 开发网站的费用属于什么费用wordpress侧边栏美化
  • 建网站的步骤和方法智慧团建官方登录
  • 网站app开发建设郏县住房和城乡建设局网站
  • 江阴网站优化公司免费查企业联系方式
  • 百度上开个网站怎么做造作网站开发
  • 中英双语网站建设东莞市建设工程监督网
  • 四川住房城乡建设厅网站首页家乡网站建设策划书