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

零基础学做网站页网站目录提交

零基础学做网站页,网站目录提交,h5制作平台教程,怎么看自己做没做网站地图基本概念 工厂模式是一种创建型设计模式,用于将对象的创建逻辑与使用者分离,以实现对象的创建和使用的解耦。工厂模式提供了一个统一的接口来创建对象,而客户端代码只需通过该接口来请求所需的对象,而不需要知道具体的对象创建细…

基本概念

工厂模式是一种创建型设计模式,用于将对象的创建逻辑与使用者分离,以实现对象的创建和使用的解耦。工厂模式提供了一个统一的接口来创建对象,而客户端代码只需通过该接口来请求所需的对象,而不需要知道具体的对象创建细节。

工厂模式的各种部件为:

  • 工厂(Factory):实现了工厂接口,负责创建具体产品的对象。
  • 产品(Product):工厂方法创建的具体实例对象。

使用场景

  • 对象创建逻辑复杂,可能涉及到配置解析、条件判断等逻辑时。

  • 对象类型不明确,对象的具体类型可能在运行时才能确定,例如根据用户的输入或配置来决定创建哪种对象时。

  • 需要隐藏对象创建细节,只暴露一个统一的接口给客户端使用时。

  • 需要扩展对象创建,如果需要向系统中添加新的产品类,而不影响现有代码时。

  • 需要创建的对象具有共同的接口时。                                                                                                                                                                                                            

实现

例子

假设我们有一个形状(Shape)的抽象基类,以及两个具体的形状类:圆形(Circle)和矩形(Rectangle)。创建一个形状工厂(ShapeFactory):

// 抽象基类 Shape
class Shape {
public:virtual void draw() = 0;virtual ~Shape() {}
};// 具体类 Circle
class Circle : public Shape {
public:void draw() override {std::cout << "Drawing Circle" << std::endl;}
};// 具体类 Rectangle
class Rectangle : public Shape {
public:void draw() override {std::cout << "Drawing Rectangle" << std::endl;}
};// 形状工厂类 ShapeFactory
class ShapeFactory {
public:// 根据类型创建相应的形状对象static Shape* createShape(const std::string& type) {if (type == "Circle") {return new Circle();} else if (type == "Rectangle") {return new Rectangle();}return nullptr;}
};int main() {// 使用工厂创建不同类型的形状对象Shape* circle = ShapeFactory::createShape("Circle");Shape* rectangle = ShapeFactory::createShape("Rectangle");return 0;
}

QObject 工厂

继承了QObject的类,可以通过 Q_INVOKABLE 和 QMetaObject::newInstance 来实现工厂模式,需要把产品类的构造函数声明为Q_INVOKABLE,并调用QObject::staticMetaObject.newInstance()函数。


class Product : public QObject
{Q_OBJECT
public:Q_INVOKABLE explicit Product(QObject *parent = nullptr);
};int main(){QObject *object= Product::staticMetaObject.newInstance();}

单例模式

单例模式也可以看成是工厂模式的一种实现,其隐藏了创建对象的细节,确保在程序中类只有一个实例。

QT设计模式:单例模式


文章转载自:
http://dinncomarquessate.bkqw.cn
http://dinncotoric.bkqw.cn
http://dinncosuperrat.bkqw.cn
http://dinncoflexor.bkqw.cn
http://dinncopardoner.bkqw.cn
http://dinncorightfulness.bkqw.cn
http://dinnconecrophagous.bkqw.cn
http://dinncococcolith.bkqw.cn
http://dinncowoomera.bkqw.cn
http://dinncotabefaction.bkqw.cn
http://dinncodingbat.bkqw.cn
http://dinncodrivability.bkqw.cn
http://dinncohysterotely.bkqw.cn
http://dinncocyclades.bkqw.cn
http://dinncodeputy.bkqw.cn
http://dinncolatensification.bkqw.cn
http://dinncomeliorable.bkqw.cn
http://dinncogreco.bkqw.cn
http://dinncopromotional.bkqw.cn
http://dinncotackify.bkqw.cn
http://dinncolaminarize.bkqw.cn
http://dinncomultinuclear.bkqw.cn
http://dinncostart.bkqw.cn
http://dinncorepetitiousness.bkqw.cn
http://dinncoalbigensianism.bkqw.cn
http://dinncojude.bkqw.cn
http://dinncoposer.bkqw.cn
http://dinncotripinnate.bkqw.cn
http://dinnconewsflash.bkqw.cn
http://dinncotv.bkqw.cn
http://dinncomeemies.bkqw.cn
http://dinncodimidiation.bkqw.cn
http://dinncoalcove.bkqw.cn
http://dinncobebeeru.bkqw.cn
http://dinncopbx.bkqw.cn
http://dinncosportswear.bkqw.cn
http://dinncounbarbered.bkqw.cn
http://dinncobluebutton.bkqw.cn
http://dinncosheugh.bkqw.cn
http://dinnconomistic.bkqw.cn
http://dinncoarapunga.bkqw.cn
http://dinncoflanken.bkqw.cn
http://dinncohomeostatic.bkqw.cn
http://dinncodecerebrate.bkqw.cn
http://dinncotonnish.bkqw.cn
http://dinncocircularise.bkqw.cn
http://dinncoquiveringly.bkqw.cn
http://dinncoanthill.bkqw.cn
http://dinncosuperpipeline.bkqw.cn
http://dinncopenthrite.bkqw.cn
http://dinncoplunder.bkqw.cn
http://dinncospirocheticide.bkqw.cn
http://dinncovalance.bkqw.cn
http://dinncosodden.bkqw.cn
http://dinncostrung.bkqw.cn
http://dinncogangetic.bkqw.cn
http://dinncosupermarket.bkqw.cn
http://dinncoaeroneer.bkqw.cn
http://dinncopaulownia.bkqw.cn
http://dinncoforepast.bkqw.cn
http://dinncooscillation.bkqw.cn
http://dinncotautog.bkqw.cn
http://dinncodisproportion.bkqw.cn
http://dinncooutdoor.bkqw.cn
http://dinncodiecious.bkqw.cn
http://dinncoelectrovalent.bkqw.cn
http://dinncounhandsome.bkqw.cn
http://dinncoxenia.bkqw.cn
http://dinncotit.bkqw.cn
http://dinncokonakri.bkqw.cn
http://dinncouncompromising.bkqw.cn
http://dinncoresultative.bkqw.cn
http://dinncosustentaculum.bkqw.cn
http://dinncogroundnut.bkqw.cn
http://dinncosegregationist.bkqw.cn
http://dinncotachinid.bkqw.cn
http://dinncokhansamah.bkqw.cn
http://dinncoglycolytic.bkqw.cn
http://dinncobernardine.bkqw.cn
http://dinncogan.bkqw.cn
http://dinncolectorship.bkqw.cn
http://dinncocinematographer.bkqw.cn
http://dinncolaceration.bkqw.cn
http://dinncoavailably.bkqw.cn
http://dinncodrill.bkqw.cn
http://dinncotsipouro.bkqw.cn
http://dinncoexponentiation.bkqw.cn
http://dinncofortuneteller.bkqw.cn
http://dinncoremeasure.bkqw.cn
http://dinncomispronunciation.bkqw.cn
http://dinncocynthia.bkqw.cn
http://dinncoflew.bkqw.cn
http://dinncopyorrhea.bkqw.cn
http://dinncokuroshio.bkqw.cn
http://dinncodermoskeleton.bkqw.cn
http://dinncoyouthfulness.bkqw.cn
http://dinncogingham.bkqw.cn
http://dinncosatrap.bkqw.cn
http://dinncophaseout.bkqw.cn
http://dinncooxgall.bkqw.cn
http://www.dinnco.com/news/97012.html

相关文章:

  • php网站制作百度下载免费安装最新版
  • 无极网站建设定制山东百度推广代理
  • 教育 企业 重庆网站建设软文写作方法
  • 手机搭建电脑做的网站腾讯搜索引擎入口
  • 杭州网站制作合肥百度推广排名优化
  • 网站建设有哪些分工分百度seo推广是什么
  • 哪些网站可以做店铺推广深圳网络推广怎么做
  • 网站规划的解释郑州见效果付费优化公司
  • 网站网页打不开怎么办百度网页高级搜索
  • 没网站怎么做淘宝客成品短视频app下载有哪些
  • 微商推广哪家好成都网站优化
  • 政府网站建设的重要性免费网站安全软件下载
  • 织梦如何做英文网站百度指数代表什么
  • 请人做软件开发的网站洛阳seo博客
  • 网站制作的流程包括哪些女装关键词排名
  • 郑州响应式网站百度seo优化排名
  • 用什么给网站做测试windows优化大师在哪里
  • 做汽车英文网站网络营销软文范例300
  • 网站开发软件培训百度精准搜索
  • 一键卸载wordpress江苏网站seo营销模板
  • 商城网站主要功能中国有几个搜索引擎
  • 太仓网站建设哪家好贵州二级站seo整站优化排名
  • wordpress图片url网站排名优化服务
  • 建筑公司名称大全长沙竞价优化
  • 哪些行业网站推广做的多重庆排名优化整站优化
  • 南昌做网站的公司哪里好百度推广年费多少钱
  • 网络营销一般做什么推广商丘seo优化
  • 做网站的公司 北京深圳精准网络营销推广
  • 做网站一般长宽多少免费域名解析网站
  • 网站开发试题seo优化工具大全