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

福州网站开发cms网站建设方案书腾讯云

福州网站开发cms,网站建设方案书腾讯云,网站主体备案,济南百度整站seo推广单例模式 单例模式保证一个类只能创建一个对象#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.hkea.cn/news/14523658/

相关文章:

  • 免费建各种网站手机小游戏网站
  • 用php做网站的方法html怎么做成网站
  • 建设返利优惠券网站网站的类型大全
  • 网站备案ip更换然后制作网页
  • 网站建好用电脑做服务器wordpress 扁平化
  • 台州网站制作教程开封网站设计
  • 怎样弄免费网站百度一下网页首页
  • 三五互联网站管理登录网址wordpress修改模板教程
  • 公司淘宝网站怎么建设的更加好企业手机网站建设渠道
  • 网站改版具体建议seo排名软件免费
  • 泰安网站建设工作室计算机网络资源网站建设论文
  • 天津建设电工证查询网站正品二手手表交易网
  • 网站开发接入支付宝东莞活动网站设计模板
  • 网站点击软件排名网页的视频怎么下载到本地
  • 网站修改字体尺寸怎么做食品餐饮网站建设
  • 佛山建站模板厂家做网站找沈阳横纵网络
  • 制作ppt的网站上海公司建立网站吗
  • 导航网站网站提交怎么做Wordpress查找替换插件
  • 成都游戏网站建设wordpress 安全吗
  • 网站首页动图怎么做可以做甩货的电商网站
  • 万网网站备案产品验证未找到该域名授权信息内蒙建设工程信息网站
  • ps制作网站产品图片仙桃建设网站
  • 静态网站开发与实施的论文wordpress制作的网站模板
  • 电商网站变化个人做网站可以吗
  • 苏州工业园区做政务网站的公司阿里邮箱企业版手机版
  • 网站开发实训心得800字硅胶模具技术支持东莞网站建设
  • 家庭网络搭建网站网站开发需要团队吗
  • 怎样建设网站卖农产品在您的网站首页添加标签
  • 小游戏网站开发需要什么技术宁波网站建设相信荣胜网络
  • iis7部署asp网站seo效果检测步骤