日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

C++设计模式-采用装饰模式用户和管理员加载不同的模块(Qt框架实现)

發(fā)布時(shí)間:2025/3/15 c/c++ 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++设计模式-采用装饰模式用户和管理员加载不同的模块(Qt框架实现) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄

?

?

基本概念

例子與實(shí)例


?

基本概念

這里在本https://blog.csdn.net/qq78442761/article/details/91379724例子的基本上,進(jìn)行擴(kuò)充與修改。

同樣,結(jié)構(gòu)圖如下

?

例子與實(shí)例

當(dāng)加載如下信息時(shí):

界面如下:

修改成如下:

界面運(yùn)行如下:

程序結(jié)構(gòu)如下:

這里只是簡(jiǎn)單處理,所有的模塊都是formxxxxxxxxx.ui和相關(guān)類組成的,按道理來(lái)說(shuō),應(yīng)該是寫到一個(gè)dll里面,調(diào)用不同的dll,進(jìn)行加載,這樣的話,耦合性就低了,而且還方便后期的維護(hù)工作。

這里的concretedcoratorX.h和.cpp是decorator的子類,decorator是透明的,寫好了就不用改。通過(guò)concretedcoratorX在operation的地方寫對(duì)應(yīng)模塊的代碼,在通過(guò)如下的代碼,進(jìn)行加載即可

詳細(xì)代碼,請(qǐng)到下面這個(gè)鏈接里面查找。

component為最關(guān)鍵的接口。他有著承上啟下的作用,關(guān)聯(lián)了comcretecomponent這個(gè)具體對(duì)象,和decorator與裝飾相關(guān)的(這里我給他稱之為與裝飾相關(guān)的中間層)。

感覺(jué)主要就是套路!

component.h

#ifndef COMPONENT_H #define COMPONENT_H#include <QObject>QT_BEGIN_NAMESPACE class QWidget; QT_END_NAMESPACEclass Component { public:virtual void processOperation(QWidget *page = nullptr);protected:Component(); };#endif // COMPONENT_H

component.cpp

#include "component.h"void Component::processOperation(QWidget *page) {Q_UNUSED(page) }Component::Component() {}

decorator.h

#ifndef DECORATOR_H #define DECORATOR_H#include "component.h"class Decorator: public Component { public:Decorator();void setComponent(Component *component);void processOperation(QWidget *page = nullptr);private:Component *m_component; };#endif // DECORATOR_H

decorator.cpp
?

#include "decorator.h" #include <QWidget> #include <QDebug>Decorator::Decorator() {m_component = nullptr; }void Decorator::setComponent(Component *component) {m_component = component;processOperation(); }void Decorator::processOperation(QWidget *page) {if(page == nullptr)return;qDebug() << "Decorator processOperation called!" << m_component;m_component->processOperation(page); }

源碼打包下載地址如下:

https://github.com/fengfanchen/Qt/tree/master/DecoratorWidget

總結(jié)

以上是生活随笔為你收集整理的C++设计模式-采用装饰模式用户和管理员加载不同的模块(Qt框架实现)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。