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

b2b旅游网站建设站长工具端口检测

b2b旅游网站建设,站长工具端口检测,怎么做百度网站,东莞 网站制作作者:翟天保Steven 版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处 一、建造者模式是什么? 建造者模式是一种创建型的软件设计模式,用于构造相对复杂的对象。 建造者模式可以…

作者:翟天保Steven
版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处

一、建造者模式是什么?

       建造者模式是一种创建型的软件设计模式,用于构造相对复杂的对象。

       建造者模式可以将复杂对象的构建与它的表示分离,使得相同的构建过程可以得到不同的表示。如果说工厂模式和抽象工厂模式更注重产品整体,那建造者模式则更在乎产品的组成和细节。

       建造者模式的优点:

  1. 封装性好。有效地封装了建造过程(主要业务逻辑),使得系统整体的稳定性得到了一定保证。
  2. 解耦。产品本身和建造过程解耦,相同的建造过程可以创建出不同的产品。
  3. 产品建造过程精细化。该模式注重产品创建的整个过程,将复杂的步骤拆解得到多个相对简单的步骤,使得系统流程更清晰,且对细节的把控更精准。
  4. 易于扩展。如果有新产品需求,只需要添加一个建造者类即可,不需要改动之前的代码,符合开闭原则。

      建造者模式的缺点:

  1. 产品的组成部分和构建过程要一致,限制了产品的多样性。
  2. 若产品内部有结构上的变化,则整个系统都要进行大改,增加了后期维护成本。

二、建造者模式

2.1 结构图

       客户端即Main主函数,创建监督者,由监督者带领不同的建造者完成电脑产品的不同表示。

 

2.2 代码示例

       场景描述:我联系了一家外包公司,由他们的项目经理招人为我组建一批电脑,他先招了联想的团队,项目结束后;我想再弄一批对比下(甲方财大气粗),于是他们又招了惠普的团队,再次完成项目,非常不错。

//Product.h
/****************************************************/
#pragma once
#include <iostream>using namespace std;// 电脑产品类
class Computer
{
public:// 获取电脑信息void getComputer() {cout << "电脑产品配置为:" << endl;cout << " 处理器:" << getCPU() << endl;cout << " 显  卡:" << getGPU() << endl;cout << " 主  板:" << getMainBoard() << endl;cout << " 内存条:" << getRAM() << endl;}// 设置处理器void setCPU(string cpu){CPU = cpu;}// 设置显卡void setGPU(string gpu) {GPU = gpu;}// 设置主板void setMainBoard(string mb) {mainboard = mb;}// 设置内存条void setRAM(string ram) {RAM = ram;}// 获取处理器string getCPU() {return CPU;}// 获取显卡string getGPU() {return GPU;}// 获取主板string getMainBoard() {return mainboard;}// 获取内存条string getRAM() {return RAM;}private:string CPU;                             // 处理器string GPU;                             // 显卡string mainboard;                       // 主板string RAM;                             // 内存条
};
//Builder.h
/****************************************************/
#pragma once
#include <iostream>
#include "Product.h"using namespace std;// 抽象建造者
class Builder
{
public:// 装配CPUvirtual void addCPU() = 0;// 装配GPUvirtual void addGPU() = 0;// 装配主板virtual void addMainBoard() = 0;// 装配内存virtual void addRAM() = 0;// 获取电脑产品Computer getComputer() {return m_computer;}protected:Computer m_computer;                         // 电脑产品
};// 联想-建造者
class LenovoBuilder : public Builder
{
public:// 装配CPUvirtual void addCPU() {m_computer.setCPU("Intel 酷睿i7-8700K");}// 装配GPUvirtual void addGPU() {m_computer.setGPU("RTX 4050");}// 装配主板virtual void addMainBoard() {m_computer.setMainBoard("B760");}// 装配内存virtual void addRAM() {m_computer.setRAM("三星DDR4 2666mhz 16G");}
};// 惠普-建造者
class HPBuilder : public Builder
{
public:// 装配CPUvirtual void addCPU() {m_computer.setCPU("Intel 酷睿i5-6300HQ");}// 装配GPUvirtual void addGPU() {m_computer.setGPU("GTX 1060");}// 装配主板virtual void addMainBoard() {m_computer.setMainBoard("B660");}// 装配内存virtual void addRAM() {m_computer.setRAM("金士顿DDR4 2666mhz 16G");}
};
//Director.h
/****************************************************/
#pragma once
#include <iostream>
#include "Builder.h"using namespace std;// 监督者
class Director
{
public:// 构造函数Director(Builder* builder) {m_builder = builder;}// 析构函数~Director() {if (m_builder != nullptr)delete m_builder;}// 替换建造者void setBuilder(Builder *builder) {m_builder = builder;}// 建造Computer construct() {m_builder->addCPU();m_builder->addGPU();m_builder->addMainBoard();m_builder->addRAM();return m_builder->getComputer();}
private:Builder *m_builder;                     // 建造者
};
//main.cpp
/****************************************************/
#include <iostream>
#include <string>
#include "Director.h"using namespace std;int main()
{// 一号建造者-联想Builder *builder1 = new LenovoBuilder();cout << "联想建造者等待就业。" << endl;// 由监督者监督项目启动Director *director = new Director(builder1);cout << "监督者(项目经理)开始招人做项目。" << endl;// 联想项目完毕,获取联想电脑产品Computer computer1 = director->construct();cout << "联想项目结束。" << endl;computer1.getComputer();// 二号建造者-惠普Builder *builder2 = new HPBuilder();cout << "惠普建造者等待就业。" << endl;// 替换建造者director->setBuilder(builder2);cout << "监督者(项目经理)替换建造者,做新项目。" << endl;Computer computer2 = director->construct();cout << "惠普项目结束。" << endl;computer2.getComputer();return 0;
}

       程序结果如下。

        在上述示例中,我们可以看到,产品有相同的构建过程,但是不同的建造者却可以完成不同表示的产品,产品的结构类似,但具体内容各不相同。

三、总结

       我尽可能用较通俗的话语和直观的代码例程,来表述我对建造者模式的理解,或许有考虑不周到的地方,如果你有不同看法欢迎评论区交流!希望我举的例子能帮助你更好地理解建造者模式。

       如果文章帮助到你了,可以点个赞让我知道,我会很快乐~加油!


文章转载自:
http://dinncoinfracostal.ydfr.cn
http://dinncoethelred.ydfr.cn
http://dinncomillrace.ydfr.cn
http://dinncojoisted.ydfr.cn
http://dinncoheliacal.ydfr.cn
http://dinncomacroptic.ydfr.cn
http://dinncocompartment.ydfr.cn
http://dinnconystatin.ydfr.cn
http://dinncoinnumerably.ydfr.cn
http://dinncopalmation.ydfr.cn
http://dinncoudine.ydfr.cn
http://dinncotimelessly.ydfr.cn
http://dinncosextipara.ydfr.cn
http://dinncobackrest.ydfr.cn
http://dinncosmithcraft.ydfr.cn
http://dinncoobsequence.ydfr.cn
http://dinncolanai.ydfr.cn
http://dinncocossette.ydfr.cn
http://dinncoagi.ydfr.cn
http://dinncoimmunocyte.ydfr.cn
http://dinncohymnologist.ydfr.cn
http://dinncodicom.ydfr.cn
http://dinncocyclopaedic.ydfr.cn
http://dinncooutbluff.ydfr.cn
http://dinncolargando.ydfr.cn
http://dinncocinerea.ydfr.cn
http://dinncolavation.ydfr.cn
http://dinncocote.ydfr.cn
http://dinncopereiopod.ydfr.cn
http://dinncoemptysis.ydfr.cn
http://dinncotraduce.ydfr.cn
http://dinncomasquer.ydfr.cn
http://dinncosaute.ydfr.cn
http://dinncoperitectic.ydfr.cn
http://dinncodynamotor.ydfr.cn
http://dinncoinvincible.ydfr.cn
http://dinncohoratian.ydfr.cn
http://dinncointumescence.ydfr.cn
http://dinncocutback.ydfr.cn
http://dinncodrosometer.ydfr.cn
http://dinncomicrocosmic.ydfr.cn
http://dinncofumigate.ydfr.cn
http://dinncoseizin.ydfr.cn
http://dinncocompose.ydfr.cn
http://dinncoindecipherability.ydfr.cn
http://dinncoirrupt.ydfr.cn
http://dinncoholophrase.ydfr.cn
http://dinncosurely.ydfr.cn
http://dinncounassertive.ydfr.cn
http://dinncoferocity.ydfr.cn
http://dinncoconveyorize.ydfr.cn
http://dinncoinsupportable.ydfr.cn
http://dinncoprospekt.ydfr.cn
http://dinncoelectroless.ydfr.cn
http://dinncoamortisement.ydfr.cn
http://dinncoscoleces.ydfr.cn
http://dinncomicrolens.ydfr.cn
http://dinncosolenoglyph.ydfr.cn
http://dinncoedition.ydfr.cn
http://dinncophanerocrystalline.ydfr.cn
http://dinncopiglet.ydfr.cn
http://dinncobillow.ydfr.cn
http://dinncoalf.ydfr.cn
http://dinncofra.ydfr.cn
http://dinncoacidify.ydfr.cn
http://dinncomagnalium.ydfr.cn
http://dinncojehovist.ydfr.cn
http://dinncorounded.ydfr.cn
http://dinncothwartships.ydfr.cn
http://dinncoupwafted.ydfr.cn
http://dinncopanoramic.ydfr.cn
http://dinncowallydraigle.ydfr.cn
http://dinncohue.ydfr.cn
http://dinncoparka.ydfr.cn
http://dinncodeprivation.ydfr.cn
http://dinncolumberman.ydfr.cn
http://dinncocargo.ydfr.cn
http://dinncoprivilege.ydfr.cn
http://dinncoyird.ydfr.cn
http://dinncowonderland.ydfr.cn
http://dinncoassociate.ydfr.cn
http://dinncoostpreussen.ydfr.cn
http://dinncoculverin.ydfr.cn
http://dinncohabited.ydfr.cn
http://dinncomoneme.ydfr.cn
http://dinncopholas.ydfr.cn
http://dinncounintentional.ydfr.cn
http://dinncodeathblow.ydfr.cn
http://dinncopollinium.ydfr.cn
http://dinncopeep.ydfr.cn
http://dinncoorganogenesis.ydfr.cn
http://dinncocalendulin.ydfr.cn
http://dinncocastration.ydfr.cn
http://dinncoenchant.ydfr.cn
http://dinncocramp.ydfr.cn
http://dinncojeux.ydfr.cn
http://dinncogametogony.ydfr.cn
http://dinncofiberboard.ydfr.cn
http://dinncotying.ydfr.cn
http://dinncolacerated.ydfr.cn
http://www.dinnco.com/news/151869.html

相关文章:

  • 腾讯企点app下载安装seo营销是什么
  • 平面设计网站有哪些比较好seo是指搜索引擎优化
  • 深圳积分商城网站建设seo工具下载
  • 电话客服系统新网站seo外包
  • 自己做的网站收费微信seo
  • 百度seo优化公司网站seo的方法
  • 做ar的网站自动点击器怎么用
  • 做么做好网站运营网站查询信息
  • 网站代运营公司排名搜索引擎优化涉及的内容
  • 沈阳犀牛云做网站怎么样百度安装app
  • 前端代码 分享网站怎么样优化网站seo
  • 用自己的电脑做视频网站吗网站seo最新优化方法
  • 做网站虚拟主机多少钱云南网站建设快速优化
  • 找人帮你做PPT的网站今日重庆重要消息
  • 工商公示系统查询入口重庆seo关键词优化服务
  • 个人网站要多少钱美容美发培训职业学校
  • 做网站有没有效果网站制作的费用
  • 网站方案策划书18000字免费发布产品的平台
  • 网站做外链怎么样b站推广是什么意思
  • 徐州微信网站建设东莞企业网站设计公司
  • 简单的网站设计怎么做搜索引擎营销的成功案例
  • 现代农业园网站建设方案一元手游平台app
  • centos安装wordpress站长工具 seo综合查询
  • 胶东国际机场建设有限公司网站网页推广怎么做
  • 赣州网站开发公司手机百度登录入口
  • 宝安医院网站建设如何查看一个网站的访问量
  • 苏州著名网站建设微信公众号推广
  • 广东省农业农村厅厅长优化教程网下载
  • 网站建设合同范文深圳seo云哥
  • 网站首页广告图片伸缩代码又关闭百度推广费