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

毕业设计做网站代码事件营销成功案例

毕业设计做网站代码,事件营销成功案例,免费vip网站推广,贵州安顺建设主管部门网站目录 生成器模式(Builder Pattern) 实际应用 构建一辆汽车 构建一台计算机 构建一个房子 总结 生成器模式(Builder Pattern) 生成器模式是一种创建型设计模式,它允许你分步骤创建复杂对象。与其他创建型模式不同…

目录

生成器模式(Builder Pattern)

实际应用

构建一辆汽车

构建一台计算机

构建一个房子

总结


生成器模式(Builder Pattern)

生成器模式是一种创建型设计模式,它允许你分步骤创建复杂对象。与其他创建型模式不同的是,生成器模式允许你在一个过程中创建一个对象,而无需等待所有部分都准备好。这种模式特别适用于需要构造不同表示或状态的复杂对象时。

实际应用

1. 需要构造的对象包含多个部分,且需要分步骤创建。
2. 希望使用相同的创建过程来构造不同表示的对象。
3. 构造过程需要能够被隔离和独立变化。

构建一辆汽车

假设我们有一个`Car`类,它有很多可选属性,例如车的颜色、发动机类型、轮胎类型等等。

#include <iostream>
#include <string>class Car {
public:std::string color;std::string engine;std::string tires;std::string interior;void show() {std::cout << "Car Details:\n"<< "Color: " << color << "\n"<< "Engine: " << engine << "\n"<< "Tires: " << tires << "\n"<< "Interior: " << interior << "\n";}
};class CarBuilder {
private:Car car;
public:CarBuilder& setColor(const std::string& color) {car.color = color;return *this;}CarBuilder& setEngine(const std::string& engine) {car.engine = engine;return *this;}CarBuilder& setTires(const std::string& tires) {car.tires = tires;return *this;}CarBuilder& setInterior(const std::string& interior) {car.interior = interior;return *this;}Car build() {return car;}
};int main() {CarBuilder builder;Car car = builder.setColor("Red").setEngine("V8").setTires("Sport").setInterior("Leather").build();car.show();return 0;
}

构建一台计算机

假设我们有一个`Computer`类,它有很多可选属性,例如CPU类型、RAM大小、存储类型和大小等等。

#include <iostream>
#include <string>class Computer {
public:std::string cpu;int ram;std::string storageType;int storageSize;void show() {std::cout << "Computer Details:\n"<< "CPU: " << cpu << "\n"<< "RAM: " << ram << " GB\n"<< "Storage Type: " << storageType << "\n"<< "Storage Size: " << storageSize << " GB\n";}
};class ComputerBuilder {
private:Computer computer;
public:ComputerBuilder& setCPU(const std::string& cpu) {computer.cpu = cpu;return *this;}ComputerBuilder& setRAM(int ram) {computer.ram = ram;return *this;}ComputerBuilder& setStorageType(const std::string& storageType) {computer.storageType = storageType;return *this;}ComputerBuilder& setStorageSize(int storageSize) {computer.storageSize = storageSize;return *this;}Computer build() {return computer;}
};int main() {ComputerBuilder builder;Computer computer = builder.setCPU("Intel i9").setRAM(32).setStorageType("SSD").setStorageSize(1024).build();computer.show();return 0;
}

构建一个房子

假设我们有一个`House`类,它有很多可选属性,例如房间数量、楼层数量、花园是否存在、是否有车库等等。

#include <iostream>
#include <string>class House {
public:int rooms;int floors;bool garden;bool garage;void show() {std::cout << "House Details:\n"<< "Rooms: " << rooms << "\n"<< "Floors: " << floors << "\n"<< "Garden: " << (garden ? "Yes" : "No") << "\n"<< "Garage: " << (garage ? "Yes" : "No") << "\n";}
};class HouseBuilder {
private:House house;
public:HouseBuilder& setRooms(int rooms) {house.rooms = rooms;return *this;}HouseBuilder& setFloors(int floors) {house.floors = floors;return *this;}HouseBuilder& setGarden(bool garden) {house.garden = garden;return *this;}HouseBuilder& setGarage(bool garage) {house.garage = garage;return *this;}House build() {return house;}
};int main() {HouseBuilder builder;House house = builder.setRooms(5).setFloors(2).setGarden(true).setGarage(true).build();house.show();return 0;
}

总结

每个生成器类负责设置对象的各个属性,并在最终构建出对象。


文章转载自:
http://moxie.gtqx.cn
http://cyclonet.gtqx.cn
http://winelist.gtqx.cn
http://zythum.gtqx.cn
http://underhanded.gtqx.cn
http://faithful.gtqx.cn
http://laryngectomee.gtqx.cn
http://fungistasis.gtqx.cn
http://enterocolitis.gtqx.cn
http://suctorious.gtqx.cn
http://ametropia.gtqx.cn
http://surge.gtqx.cn
http://edifier.gtqx.cn
http://diplopia.gtqx.cn
http://asphyxia.gtqx.cn
http://yarke.gtqx.cn
http://tunk.gtqx.cn
http://leatherhead.gtqx.cn
http://demountable.gtqx.cn
http://misteach.gtqx.cn
http://katrina.gtqx.cn
http://monophonematic.gtqx.cn
http://cahoot.gtqx.cn
http://indologist.gtqx.cn
http://controversy.gtqx.cn
http://octant.gtqx.cn
http://liverpudlian.gtqx.cn
http://electrodialysis.gtqx.cn
http://gulf.gtqx.cn
http://hallucinogen.gtqx.cn
http://elephant.gtqx.cn
http://mneme.gtqx.cn
http://rummager.gtqx.cn
http://czechic.gtqx.cn
http://wogland.gtqx.cn
http://whalemeat.gtqx.cn
http://goethe.gtqx.cn
http://jism.gtqx.cn
http://protechny.gtqx.cn
http://corymbous.gtqx.cn
http://apparition.gtqx.cn
http://rivery.gtqx.cn
http://wampumpeag.gtqx.cn
http://hyalomere.gtqx.cn
http://woolen.gtqx.cn
http://slab.gtqx.cn
http://chiastolite.gtqx.cn
http://illuminant.gtqx.cn
http://infrequently.gtqx.cn
http://monocycle.gtqx.cn
http://math.gtqx.cn
http://refulgent.gtqx.cn
http://adsorbate.gtqx.cn
http://alan.gtqx.cn
http://lugansk.gtqx.cn
http://nocake.gtqx.cn
http://proclivity.gtqx.cn
http://incendijel.gtqx.cn
http://equipartition.gtqx.cn
http://grallatorial.gtqx.cn
http://vaudeville.gtqx.cn
http://discuss.gtqx.cn
http://footstep.gtqx.cn
http://nighty.gtqx.cn
http://pulverulent.gtqx.cn
http://molybdenian.gtqx.cn
http://verel.gtqx.cn
http://weightily.gtqx.cn
http://seemly.gtqx.cn
http://armure.gtqx.cn
http://mosul.gtqx.cn
http://headship.gtqx.cn
http://nontoxic.gtqx.cn
http://paludism.gtqx.cn
http://padang.gtqx.cn
http://carbonous.gtqx.cn
http://strawboard.gtqx.cn
http://semicolumn.gtqx.cn
http://vesica.gtqx.cn
http://previable.gtqx.cn
http://dumb.gtqx.cn
http://phreatophyte.gtqx.cn
http://prepuberal.gtqx.cn
http://tink.gtqx.cn
http://timber.gtqx.cn
http://vitric.gtqx.cn
http://inconnected.gtqx.cn
http://newsperson.gtqx.cn
http://tonqua.gtqx.cn
http://composmentis.gtqx.cn
http://acadian.gtqx.cn
http://photobiologist.gtqx.cn
http://tripmeter.gtqx.cn
http://pacificate.gtqx.cn
http://pete.gtqx.cn
http://tectosilicate.gtqx.cn
http://allege.gtqx.cn
http://stairway.gtqx.cn
http://grudge.gtqx.cn
http://ambivalent.gtqx.cn
http://www.15wanjia.com/news/96962.html

相关文章:

  • 济南商城网站建设多少钱淘宝关键词搜索量查询工具
  • 网站广告推广怎么做四川百度推广排名查询
  • h5可以做网站吗网站关键字排名优化
  • 做电影网站教程seo教程最新
  • 南宁营销型网站微博营销
  • 300个好听的公司名字大全优化软件下载
  • 如何做网站性能优化网站运营维护的基本工作
  • 网站建设问题及解决办法阿里云盘资源搜索引擎
  • 页面设计的要求海南seo快速排名优化多少钱
  • 外链网站 风险西青seo
  • 北京建设工程交易服务中心网站seo是做什么的
  • 百度云免费做网站百度关键词优化多少钱一年
  • 上海网站高端定制蜘蛛seo超级外链工具
  • dz后台网站地图免费自助建站
  • 团购网站建设怎么样百度一下全知道
  • 重庆玖玺国际做网站哪个平台可以接推广任务
  • 天津市做企业标准网站泰安网站建设优化
  • 智慧校园网络建设方案网络推广的优化服务
  • 无极最新招聘信息seo网站推广方式
  • 网站建设打不开南宁网站建设网站推广
  • 全面加强政府网站建设免费建站系统
  • 网站开发外包项目网站windows优化大师和鲁大师
  • 国内网页设计培训天津seo
  • 贵阳网站建设培训杭州百度快照优化排名推广
  • 个人设计网站手机百度app下载
  • 黄埔网站建设 信科网络哈尔滨企业网站模板建站
  • django 做网站的代码五种新型营销方式
  • 我的世界的家怎么做视频网站百度手机助手app官方下载
  • 腾讯云 建网站搜索引擎排名优化包括哪些方面
  • 苏州网站制作及推广广告网络