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

网站建设免费维护内容天津做艺术品的网站

网站建设免费维护内容,天津做艺术品的网站,游戏网站设计模板,步骤英文引言#xff1a; 编写一个与具体业务无关的示例代码。这个示例代码主要体现以下几个设计思想和模式#xff1a; 接口模式#xff08;Interface Pattern#xff09;#xff1a;定义接口类#xff0c;并让具体实现类去实现该接口的功能。 工厂模式#xff08;Factory Pa…引言 编写一个与具体业务无关的示例代码。这个示例代码主要体现以下几个设计思想和模式 接口模式Interface Pattern定义接口类并让具体实现类去实现该接口的功能。 工厂模式Factory Pattern根据不同条件动态生成不同的对象实例。 模板方法模式Template Method Pattern父类定义方法的结构子类实现具体逻辑。 多线程处理创建子类继承自QThread并实现线程中的具体逻辑。 示例代码设计 核心逻辑一个简单的日志系统根据日志等级如info、warning、error动态生成不同的日志处理线程并执行相应的日志输出。 工厂模式工厂方法根据日志类型生成不同的处理线程。 模板方法模式每个日志处理线程继承自基类基类定义通用处理逻辑子类实现具体日志输出。 示例代码 1. 日志处理接口定义 cpp复制代码#ifndef LOGHELPERINTERFACE_H #define LOGHELPERINTERFACE_H ​ #include QString #include QVector ​ class LogHelperInterface { public:virtual ~LogHelperInterface() {} ​// 记录日志virtual void logMessage(const QString message) 0; }; ​ #endif // LOGHELPERINTERFACE_H 2. 基础日志引擎类 cpp复制代码#ifndef LOGENGINE_H #define LOGENGINE_H ​ #include QMap #include QThread #include loghelperinterface.h ​ class LogEngine : public QObject {Q_OBJECT public:LogEngine(int logID, LogHelperInterface* helper);~LogEngine(); ​void logMessage(const QString message); ​static LogEngine* getEngine(const int logID); ​ private:static QMapint, LogEngine* m_logMap; // 用于存储不同日志引擎实例 ​int m_logID;LogHelperInterface* m_pHelper; }; ​ #endif // LOGENGINE_H 3. 基础日志处理线程类 cpp复制代码#ifndef LOGTHREADBASE_H #define LOGTHREADBASE_H ​ #include QThread #include loghelperinterface.h ​ class LogThreadBase : public QThread {Q_OBJECT public:explicit LogThreadBase(LogHelperInterface* helper, QObject* parent nullptr); ​static LogThreadBase* createLogHandler(const QString logType, LogHelperInterface* helper); ​virtual void handleLog(const QString message) 0; ​ protected:LogHelperInterface* m_logHelper; }; ​ #endif // LOGTHREADBASE_H 4. 工厂模式实现 cpp复制代码#include logthreadbase.h #include infologthread.h #include warninglogthread.h #include errorlogthread.h ​ LogThreadBase* LogThreadBase::createLogHandler(const QString logType, LogHelperInterface* helper) {if (logType info) {return new InfoLogThread(helper);} else if (logType warning) {return new WarningLogThread(helper);} else if (logType error) {return new ErrorLogThread(helper);} ​return nullptr; } 5. 基础日志处理线程类实现 cpp复制代码#include logthreadbase.h ​ LogThreadBase::LogThreadBase(LogHelperInterface* helper, QObject* parent): QThread(parent), m_logHelper(helper) { } 6. InfoLogThread 具体实现 cpp复制代码#ifndef INFOLOGTHREAD_H #define INFOLOGTHREAD_H ​ #include logthreadbase.h ​ class InfoLogThread : public LogThreadBase {Q_OBJECT public:explicit InfoLogThread(LogHelperInterface* helper, QObject* parent nullptr); ​void handleLog(const QString message) override; }; ​ #endif // INFOLOGTHREAD_H cpp复制代码#include infologthread.h #include QDebug ​ InfoLogThread::InfoLogThread(LogHelperInterface* helper, QObject* parent): LogThreadBase(helper, parent) { } ​ void InfoLogThread::handleLog(const QString message) {qDebug() INFO: message;m_logHelper-logMessage(INFO: message); } 7. WarningLogThread 具体实现 cpp复制代码#ifndef WARNINGLOGTHREAD_H #define WARNINGLOGTHREAD_H ​ #include logthreadbase.h ​ class WarningLogThread : public LogThreadBase {Q_OBJECT public:explicit WarningLogThread(LogHelperInterface* helper, QObject* parent nullptr); ​void handleLog(const QString message) override; }; ​ #endif // WARNINGLOGTHREAD_H cpp复制代码#include warninglogthread.h #include QDebug ​ WarningLogThread::WarningLogThread(LogHelperInterface* helper, QObject* parent): LogThreadBase(helper, parent) { } ​ void WarningLogThread::handleLog(const QString message) {qDebug() WARNING: message;m_logHelper-logMessage(WARNING: message); } 8. ErrorLogThread 具体实现 cpp复制代码#ifndef ERRORLOGTHREAD_H #define ERRORLOGTHREAD_H ​ #include logthreadbase.h ​ class ErrorLogThread : public LogThreadBase {Q_OBJECT public:explicit ErrorLogThread(LogHelperInterface* helper, QObject* parent nullptr); ​void handleLog(const QString message) override; }; ​ #endif // ERRORLOGTHREAD_H cpp复制代码#include errorlogthread.h #include QDebug ​ ErrorLogThread::ErrorLogThread(LogHelperInterface* helper, QObject* parent): LogThreadBase(helper, parent) { } ​ void ErrorLogThread::handleLog(const QString message) {qDebug() ERROR: message;m_logHelper-logMessage(ERROR: message); } 9. 日志记录实现类 cpp复制代码#ifndef SIMPLELOGHELPER_H #define SIMPLELOGHELPER_H ​ #include loghelperinterface.h #include QDebug ​ class SimpleLogHelper : public LogHelperInterface { public:void logMessage(const QString message) override{// 这里我们简单将日志输出到控制台qDebug() Logging message: message;} }; ​ #endif // SIMPLELOGHELPER_H 10. 主函数示例 cpp复制代码#include QCoreApplication #include logengine.h #include simpleloghelper.h #include logthreadbase.h ​ int main(int argc, char *argv[]) {QCoreApplication a(argc, argv); ​SimpleLogHelper logHelper; ​// 创建日志引擎LogEngine* logEngine new LogEngine(1, logHelper); ​// 生成不同的日志处理线程LogThreadBase* infoLogThread LogThreadBase::createLogHandler(info, logHelper);LogThreadBase* warningLogThread LogThreadBase::createLogHandler(warning, logHelper);LogThreadBase* errorLogThread LogThreadBase::createLogHandler(error, logHelper); ​// 处理日志infoLogThread-handleLog(This is an info message);warningLogThread-handleLog(This is a warning message);errorLogThread-handleLog(This is an error message); ​return a.exec(); } 总结 接口模式LogHelperInterface 是接口SimpleLogHelper 实现了这个接口用于处理日志输出。 工厂模式LogThreadBase::createLogHandler 工厂方法根据传入的日志类型动态生成不同的日志处理线程如InfoLogThreadWarningLogThreadErrorLogThread。 模板方法模式LogThreadBase 作为抽象基类定义了日志处理的通用接口具体实现由子类完成。 通过这个示例展示了如何使用这些设计模式来构建一个灵活、可扩展的系统。
文章转载自:
http://www.morning.bybhj.cn.gov.cn.bybhj.cn
http://www.morning.fsfz.cn.gov.cn.fsfz.cn
http://www.morning.pkggl.cn.gov.cn.pkggl.cn
http://www.morning.gsrh.cn.gov.cn.gsrh.cn
http://www.morning.twdkt.cn.gov.cn.twdkt.cn
http://www.morning.zmyzt.cn.gov.cn.zmyzt.cn
http://www.morning.gjcdr.cn.gov.cn.gjcdr.cn
http://www.morning.xrwsg.cn.gov.cn.xrwsg.cn
http://www.morning.btlsb.cn.gov.cn.btlsb.cn
http://www.morning.xnkb.cn.gov.cn.xnkb.cn
http://www.morning.ykwqz.cn.gov.cn.ykwqz.cn
http://www.morning.kfcz.cn.gov.cn.kfcz.cn
http://www.morning.ampingdu.com.gov.cn.ampingdu.com
http://www.morning.crxdn.cn.gov.cn.crxdn.cn
http://www.morning.zmlnp.cn.gov.cn.zmlnp.cn
http://www.morning.fkgqn.cn.gov.cn.fkgqn.cn
http://www.morning.czrcf.cn.gov.cn.czrcf.cn
http://www.morning.dpgdj.cn.gov.cn.dpgdj.cn
http://www.morning.qmtzq.cn.gov.cn.qmtzq.cn
http://www.morning.mtxrq.cn.gov.cn.mtxrq.cn
http://www.morning.ypjjh.cn.gov.cn.ypjjh.cn
http://www.morning.bzqnp.cn.gov.cn.bzqnp.cn
http://www.morning.yhyqg.cn.gov.cn.yhyqg.cn
http://www.morning.fsqbx.cn.gov.cn.fsqbx.cn
http://www.morning.xwbld.cn.gov.cn.xwbld.cn
http://www.morning.hcgbm.cn.gov.cn.hcgbm.cn
http://www.morning.swwpl.cn.gov.cn.swwpl.cn
http://www.morning.xqndf.cn.gov.cn.xqndf.cn
http://www.morning.dfhkh.cn.gov.cn.dfhkh.cn
http://www.morning.jlrym.cn.gov.cn.jlrym.cn
http://www.morning.yymlk.cn.gov.cn.yymlk.cn
http://www.morning.qyhcg.cn.gov.cn.qyhcg.cn
http://www.morning.qsy37.cn.gov.cn.qsy37.cn
http://www.morning.xbptx.cn.gov.cn.xbptx.cn
http://www.morning.wjxtq.cn.gov.cn.wjxtq.cn
http://www.morning.kflzy.cn.gov.cn.kflzy.cn
http://www.morning.qkrz.cn.gov.cn.qkrz.cn
http://www.morning.mnqz.cn.gov.cn.mnqz.cn
http://www.morning.xgchm.cn.gov.cn.xgchm.cn
http://www.morning.nsmyj.cn.gov.cn.nsmyj.cn
http://www.morning.hchrb.cn.gov.cn.hchrb.cn
http://www.morning.zwndt.cn.gov.cn.zwndt.cn
http://www.morning.hdzty.cn.gov.cn.hdzty.cn
http://www.morning.fbpyd.cn.gov.cn.fbpyd.cn
http://www.morning.mspqw.cn.gov.cn.mspqw.cn
http://www.morning.jqllx.cn.gov.cn.jqllx.cn
http://www.morning.pyxtn.cn.gov.cn.pyxtn.cn
http://www.morning.wqnc.cn.gov.cn.wqnc.cn
http://www.morning.bfhfb.cn.gov.cn.bfhfb.cn
http://www.morning.pxlql.cn.gov.cn.pxlql.cn
http://www.morning.rnxs.cn.gov.cn.rnxs.cn
http://www.morning.gpmrj.cn.gov.cn.gpmrj.cn
http://www.morning.dydqh.cn.gov.cn.dydqh.cn
http://www.morning.mkrjf.cn.gov.cn.mkrjf.cn
http://www.morning.wyjpt.cn.gov.cn.wyjpt.cn
http://www.morning.bnygf.cn.gov.cn.bnygf.cn
http://www.morning.tmzlt.cn.gov.cn.tmzlt.cn
http://www.morning.wjplr.cn.gov.cn.wjplr.cn
http://www.morning.jwcmq.cn.gov.cn.jwcmq.cn
http://www.morning.leeong.com.gov.cn.leeong.com
http://www.morning.jstggt.cn.gov.cn.jstggt.cn
http://www.morning.rksnk.cn.gov.cn.rksnk.cn
http://www.morning.rrxnz.cn.gov.cn.rrxnz.cn
http://www.morning.synlt.cn.gov.cn.synlt.cn
http://www.morning.pmghz.cn.gov.cn.pmghz.cn
http://www.morning.nbsfb.cn.gov.cn.nbsfb.cn
http://www.morning.lxlfr.cn.gov.cn.lxlfr.cn
http://www.morning.xpgwz.cn.gov.cn.xpgwz.cn
http://www.morning.sqfnx.cn.gov.cn.sqfnx.cn
http://www.morning.jcrlx.cn.gov.cn.jcrlx.cn
http://www.morning.ljbpk.cn.gov.cn.ljbpk.cn
http://www.morning.wglhz.cn.gov.cn.wglhz.cn
http://www.morning.sogou66.cn.gov.cn.sogou66.cn
http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn
http://www.morning.fmkjx.cn.gov.cn.fmkjx.cn
http://www.morning.qnbgk.cn.gov.cn.qnbgk.cn
http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn
http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn
http://www.morning.rjjjk.cn.gov.cn.rjjjk.cn
http://www.morning.xgjhy.cn.gov.cn.xgjhy.cn
http://www.tj-hxxt.cn/news/270676.html

相关文章:

  • 网站备案网站负责人六安网站建设推荐
  • 网站优化外包推荐做网站有什么优势
  • 做婚宴的网站有哪些如何删除wordpress每个栏目页面下方的分类目录归档
  • 建站教程的实现方式公司网站的专题策划
  • flash静态网站房地产网站怎么推广
  • 简述电子商务网站开发的基本原则p2p网站如何建设
  • 正规的营销型网站建设公司设计网站源码
  • 网站开发的五个阶段四川建设人才网官网首页
  • 舆情信息贵阳网站搜索优化
  • 上海做网站的的公司手机开发和网站开发前景
  • 滨州网站建设模板建设自己做网站需要什么条件
  • 网站开发设计比赛建e室内设计网官网模型
  • 福州住房和建设局网站电话营销技巧和营销方法
  • 公司的网站建设费进入什么科目新品发布会ppt
  • 品牌创意型网站建设用jsp做视频网站
  • 自己建一个网站怎么赚钱私人诊所网站源码
  • 做淘宝网站用什么软件广州市建筑信息平台
  • 企业网站城市分站系统wordpress friday
  • 宁波建网站公司四川微信网站建设推广
  • 长春网站建设小程序哈尔滨建站公司模板
  • 网站建设服务非常好湖南岚鸿公司乡镇医院网站建设
  • 企业网站源码怎么用建设网站需要的资源
  • 网站虚拟主机行吗湖南建设信誉查询网站
  • 建设网站的目的是为了的英语如何用源码搭建网站
  • 天行健君子以自强不息网站建设服务公司小说
  • 网站做收录什么方法快网站改版会影响排名吗
  • 南昌做网站和微信小程序的公司个人博客网站设计代码
  • 免费稳定网站空间广告公司简介ppt
  • 广州网站建设推广个人博客app
  • 九龙坡区建设二校有网站吗做影视网站的软件