平东网站建设php网站备份

news/2025/10/1 9:08:52/文章来源:
平东网站建设,php网站备份,网上怎么开店卖产品,wordpress个人博客模板前言 创建型为了创建东西才是有用的#xff0c;创建型设计模式使用的场景#xff1a; 1、创建一个东西#xff1b; 2、可重复利用#xff1b; 3、灵活性高#xff0c;代码可因地制宜。 Factory Method(工厂模式) 工厂模式将目的将创建对象的具体过程屏蔽隔离起来#…前言 创建型为了创建东西才是有用的创建型设计模式使用的场景 1、创建一个东西 2、可重复利用 3、灵活性高代码可因地制宜。 Factory Method(工厂模式) 工厂模式将目的将创建对象的具体过程屏蔽隔离起来从而达到更高的灵活性工厂模式可以分为三类 简单工厂模式(Simple Factory)工厂方法模式(Factory Method)抽象工厂模式(Abstract Factory) 这三种模式从上到下逐步抽象并且更具一般性。《设计模式》一书中将工厂模式分为两类工厂方法模式与抽象工厂模式。将简单工厂模式看为工厂方法模式的一种特例两者归为一类。 Simple Factory(简单工厂) 主要用于创建对象。新添加类时不会影响以前的系统代码。核心思想是用一个工厂来根据输入的条件产生不同的类然后根据不同类的 virtual 函数得到不同的结果。 GOOD适用于不同情况创建不同的类时 BUG客户端必须要知道基类和工厂类耦合性差 simpleFactory.h #ifndef CLION_TEST_SIMPLEFACTORY_H #define CLION_TEST_SIMPLEFACTORY_H//基类 class COperation { public:int m_nFirst;int m_nSecond;virtual double GetResult() {double dResult 0;return dResult;} };//加法 class AddOperation : public COperation { public:double GetResult() final {return m_nFirst m_nSecond;} };//减法 class SubOperation : public COperation { public:double GetResult() final {return m_nFirst - m_nSecond;} };//工厂类 class CCalculatorFactory { public:static COperation *Create(char cOperator) {COperation *oper;switch (cOperator) {case :oper new AddOperation();break;case -:oper new SubOperation();break;default:oper new AddOperation();break;}return oper;} };#endif //CLION_TEST_SIMPLEFACTORY_Hmain.cpp #include iostream #include simpleFactory.husing namespace std;int main() {int a 1;int b 2;COperation * opCCalculatorFactory::Create(-);op-m_nFirsta;op-m_nSecondb;coutop-GetResult()endl;return 0; }Factory Method(工厂方法) GOOD修正了简单工厂模式中不遵守开放封闭原则。工厂方法模式把选择判断移到了客户端去实现如果想添加新功能就不用修改原来的类直接修改客户端即可。 一个产品对应一个工厂类。 factorymethod.h #ifndef CLION_TEST_FACTORYMETHOD_H #define CLION_TEST_FACTORYMETHOD_H#include iostream #include stringusing namespace std;// 实例基类相当于Product class LeiFeng { public:virtual void Sweep() {cout 雷锋扫地 endl;} };// 学雷锋的大学生相当于ConcreteProduct class Student : public LeiFeng { public:void Sweep() final {cout 大学生扫地 endl;} };// 学雷锋的志愿者相当于ConcreteProduct class Volenter : public LeiFeng { public:void Sweep() final {cout 志愿者 endl;} };// 工厂基类 Creator class LeiFengFactory { public:virtual LeiFeng *CreateLeiFeng() {return new LeiFeng();} };// 工厂具体类 class StudentFactory : public LeiFengFactory { public:LeiFeng *CreateLeiFeng() final {return new Student();} };class VolenterFactory : public LeiFengFactory { public:LeiFeng* CreateLeiFeng() final {return new Volenter();} };#endif //CLION_TEST_FACTORYMETHOD_Hmain.cpp #include factorymethod.husing namespace std;int main() {// 工厂方法LeiFengFactory *sf new StudentFactory();LeiFeng *s sf-CreateLeiFeng();s-Sweep();delete sf;delete s;sf nullptr;s nullptr;return 0; } Abstract Factory(抽象工厂) GOOD定义了一个创建一系列相关或相互依赖的接口而无需指定它们的具体类。 用于交换产品系列如 ACCESS­SQL SERVER 产品的具体类名被具体工厂的实现分离 abstractfactory.h #ifndef CLION_TEST_ABSTRACTFACTORY_H #define CLION_TEST_ABSTRACTFACTORY_H#include iostreamusing namespace std;// 用户抽象接口 class IUser { public:virtual void GetUser() 0;virtual void InsertUser() 0; };// 部门抽象接口 class IDepartment { public:virtual void GetDepartment() 0;virtual void InsertDepartment() 0; };// ACCESS用户 class CAccessUser : public IUser { public:void GetUser() final {cout Access GetUser endl;}void InsertUser() final {cout Access InsertUser endl;} };// ACCESS部门 class CAccessDepartment : public IDepartment { public:void GetDepartment() final {cout Access GetDepartment endl;}void InsertDepartment() final {cout Access InsertDepartment endl;} };// SQL用户 class CSqlUser : public IUser { public:void GetUser() final {cout Sql User endl;}void InsertUser() final {cout Sql User endl;} };// SQL部门类 class CSqlDepartment : public IDepartment { public:void GetDepartment() final {cout sql getDepartment endl;}void InsertDepartment() final {cout sql insertdepartment endl;} };// 抽象工厂 class IFactory { public:virtual IUser *CreateUser() 0;virtual IDepartment *CreateDepartment() 0; };// ACCESS工厂 class AccessFactory : public IFactory { public:IUser *CreateUser() final {return new CAccessUser();}IDepartment *CreateDepartment() final {return new CAccessDepartment();} };// SQL工厂 class SqlFactory : public IFactory { public:IUser *CreateUser() final {return new CSqlUser();}IDepartment *CreateDepartment() final {return new CSqlDepartment();} };#endif //CLION_TEST_ABSTRACTFACTORY_Hmain.cpp #include abstractfactory.husing namespace std;int main() {system(chcp 65001);// 抽象工厂模式///coutSQL用户endl;IFactory* factory new SqlFactory();IUser* user factory-CreateUser();IDepartment* department factory-CreateDepartment();user-GetUser();department-GetDepartment();///coutACCESS用户endl;factory new AccessFactory();user factory-CreateUser();department factory-CreateDepartment();user-GetUser();department-GetDepartment();return 0; } Builder(建造者) GOOD在当创建复杂对象的算法应该独立于该对象的组成部分以及它们的装配方式时适用。 builder.h #ifndef CLION_TEST_BUILDER_H #define CLION_TEST_BUILDER_H#include string #include iostream #include vectorusing namespace std;// 最终的产品类 class Product { private:vectorstring m_product; public:void Add(string strtemp) {m_product.push_back(strtemp);}void Show() {for (auto p m_product.begin(); p ! m_product.end(); p) {cout *p endl;}} };// 建设者基类 class Builder { public:virtual void BuilderA() 0;virtual void BuilderB() 0;virtual Product *GetResult() 0; };// 第一种建造方式 class ConcreteBuilder1 : public Builder { private:Product *m_proudct; public:ConcreteBuilder1() {m_proudct new Product();}void BuilderA() final {m_proudct-Add(one);}void BuilderB() final {m_proudct-Add(two);}Product *GetResult() final {return m_proudct;} };// 第二种建造方式 class ConcreteBuilder2 : public Builder { private:Product *m_proudct; public:ConcreteBuilder2() {m_proudct new Product();}void BuilderA() final {m_proudct-Add(A);}void BuilderB() final {m_proudct-Add(B);}Product *GetResult() final {return m_proudct;} };// 指挥者类 class Direct { public:void Construct(Builder *temp) {temp-BuilderA();temp-BuilderB();} };#endif //CLION_TEST_BUILDER_Hmain.cpp #include builder.h using namespace std;int main() {system(chcp 65001);// 建造者模式Direct *p new Direct();Builder* b1 new ConcreteBuilder1();Builder* b2 new ConcreteBuilder2();p-Construct(b1); // 调用第一种方式Product* pb1 b1-GetResult();pb1-Show();p-Construct(b2); // 调用第二种方式Product* pb2 b2-GetResult();pb2-Show();return 0; }Prototype(原型) GOOD从一个对象再创建另外一个可定制的对象而无需知道任何创建的细节。并能提高创建的性能。 说白了就 COPY 技术把一个对象完整的 COPY 出一份。 注此处书写的是浅拷贝当需要复制的内容更改时不影响原先的内容需要进行深拷贝好奇地是原型模式直接使用拷贝赋值或拷贝构造函数不就可以了嘛。 prototype.h #ifndef CLION_TEST_PROTOTYPE_H #define CLION_TEST_PROTOTYPE_H#include iostream #include vector #include stringusing namespace std;// 抽象基类 class Prototype { private:string m_strName; public:Prototype(string strName) { m_strName strName; }Prototype() { m_strName ; }void Show() {cout m_strName endl;}virtual Prototype *Clone() 0; };// class ConcretePrototype1 class ConcretePrototype1 : public Prototype { public:ConcretePrototype1(string strName) : Prototype(strName) {}ConcretePrototype1() {}Prototype *Clone() final {ConcretePrototype1 *p new ConcretePrototype1();*p *this; // 复制对象return p;} };// class ConcretePrototype2 class ConcretePrototype2 : public Prototype { public:ConcretePrototype2(string strName) : Prototype(strName) {}ConcretePrototype2() {}Prototype *Clone() final {ConcretePrototype2 *p new ConcretePrototype2();*p *this; // 复制对象return p;} };#endif //CLION_TEST_PROTOTYPE_Hmain.cpp #include iostream #include prototype.husing namespace std;int main() {system(chcp 65001);// 客户端ConcretePrototype1* test1 new ConcretePrototype1(小王);ConcretePrototype2* test2 (ConcretePrototype2*)test1-Clone();test1-Show();test2-Show();return 0; }Singleton(单例) 后记

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/923694.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

react用于网站开发仿煎蛋wordpress

添加swap交换分区SWAP即交换分区是一种类似于Windows系统虚拟内存的功能,将一部分硬盘空间虚拟成内存来使用,从而解决内存容量不足的情况,因为SWAP毕竟是用硬盘资源虚拟的,所以速度上比真实物理内存要慢很多,一般只有当…

完整教程:C++设计模式之结构型模式:适配器模式(Adapter)

完整教程:C++设计模式之结构型模式:适配器模式(Adapter)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Conso…

第三方应用测试:【移动应用后端API自动化测试:Postman与Newman的集成】 - 指南

第三方应用测试:【移动应用后端API自动化测试:Postman与Newman的集成】 - 指南pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-f…

(附源码)基于Spring Boot的宿舍管理系统设计与建立0007

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

深入解析:【项目】Vision Master OpenCV 3.0 版本(预)发行说明

深入解析:【项目】Vision Master OpenCV 3.0 版本(预)发行说明pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Co…

Adobe Acrobat Pro DC 2025版破解版下载及安装使用教程

Adobe Acrobat Pro DC 2025版破解版下载及安装使用教程Adobe Acrobat Pro DC 2025是一款功能强大的PDF文档编辑和管理工具。这款软件内置了多种编辑和修复工具,能够帮助用户方便地创建、编辑、转换和共享PDF文档。不仅…

网页访问速度很慢,远程仓库调用很慢

访问测试一下IPv6 测试 ipv6失败就去 搜索——>控制面板——>网络与internet——>网络和共享中心——>修改设配器设置——>右击那个WLAN——>属性——>把下面那个ipv6协议关了——>确认然后没…

免费网站推广工具浙江平安建设信息系统网站

前言 在持续集成/持续部署(CI/CD)的旅途中,Jenkins与版本控制系统的紧密集成是不可或缺的一环。本篇“持续集成03--Jenkins结合Gitee创建项目”将引导如何将Jenkins与Gitee(一个流行的Git代码托管平台)相结合&#xff…

详细介绍:Day51 时钟系统与定时器(EPIT/GPT)

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

郑州惠济区建设局网站删除wordpress logo

一、虚拟机简介 1、Java 虚拟机 (1) 虚拟机: 虚拟机(Virtual Machine)是一种软件或硬件实体,它模拟了一个独立的计算环境,可以在其上运行应用程序。 虚拟机可分为系统虚拟机和程序虚拟机: ● 系统虚拟…

网站推广效果的评价指标有网页游戏哪个平台最好

还在担心网购服装对实际穿着效果没把握吗?随着京东App 6.6.3版本的更新,京东试试3D虚拟试衣功能正式上线,消费者可按照自己的身材比例创建专属的3D模型,而试穿效果则可以完全依照模型来展现。据了解,这个系统未来还将实…

网站开发敬请期待dw软件代码大全

阅读导航 引言一、线程池简单介绍二、Linux下线程池代码⭕Makefile文件⭕ . h 头文件✅Task.hpp✅thread.hpp✅threadPool.hpp ⭕ . cpp 文件✅testMain.cpp 三、线程池的优点温馨提示 引言 在Linux下,线程池是一种常见的并发编程模型,它能够有效地管理…

网站建设用图工作室网站建设的意义

时间限制 :1000 ms 内存限制:65536 KB 在一个旧式的火车站旁边有一座桥,其桥面可以绕河中心的桥墩水平旋转。一个车站的职工发现桥的长度最多能容纳两节车厢,如果将桥旋转180度,则可以把相邻两节车厢的位…

网页设计公司建网站网站设计南充建设工程信息网

如果你是一个硬件系统管理员或者Linux工程师,你可能会记得大多数Linux命令行技巧。下面的这些Linux命令行技巧通常不被Linux用户所使用。 1.使用pgrep快速查找一个PID pgrep遍历目前正在运行的进程然后列出符合查找规则的进程ID(PID)。 pg…

2025木方厂家权威推荐榜:实力工厂与优质供应之选

在建筑行业持续升级的背景下,木方作为基础建材的需求呈现出专业化、品质化的发展趋势。随着绿色建筑理念的普及和施工标准的提高,市场对木方产品的稳定性、耐久性和环保性能提出了更高要求。不同规模的工程项目在选材…

2017网站开发合同下载页面设计是什么专业

爱剪辑学习委员会提醒您:道路千万条,学习第一条。教程不学会,制作两行泪。今天教大家制作炫彩的动态标题文字特效,3步即可快速学会,让你立马不再流泪。爱剪辑官网下载:http://www.aijianji.com/爱剪辑LOGO效…

LoRa/LoRaWAN技术手册

第一部分 快速入门 第一章 第二部分 基础知识 第三部分 设备 第四部分 基站 第五部分 ChirpStack与App 第六部分 运维

便宜的 VPS

hostsailor https://clients.hostsailor.com/aff.php?aff=1356