对购物网站建设的建议怎样在wordpress设置伪静态

张小明 2026/1/11 9:16:02
对购物网站建设的建议,怎样在wordpress设置伪静态,oppo手机网站建设需求分析,wordpress很卡一、原型模式 1.1、定义 原型实例指定创建对象的种类#xff0c;并通过拷贝这些原型#xff0c;创建新的对象。即克隆#xff0c;细胞分裂等。 1.2、核心思想 通过复制现有对象(原型)来创建新对象#xff0c;而不是通过new新建实例 1.3、为什么需要原型模式 问题场景 创建角…一、原型模式1.1、定义原型实例指定创建对象的种类并通过拷贝这些原型创建新的对象。即克隆细胞分裂等。1.2、核心思想通过复制现有对象(原型)来创建新对象而不是通过new新建实例1.3、为什么需要原型模式问题场景创建角色以孙悟空为例// 装备类classEquipment{private:std::string name;intpower;public:Equipment(std::string name,intpower):name(name),power(power){}Equipment*clone()const{returnnewEquipment(name,power);}std::stringgetName()const{returnname;}intgetPower()const{returnpower;}voiddisplay()const{std::cout name (威力:power)std::endl;}};classSunWuKong{private:std::string name;inthealth;intattack;std::vectorstd::stringskills;std::vectorEquipment*equipment;public:SunWuKong(std::string name,inthealth,intattack):name(name),health(health),attack(attack){// 初始化技能skills.push_back(七十二变);skills.push_back(筋斗云);skills.push_back(火眼金睛);skills.push_back(法天象地);skills.push_back(身外身);// 初始化装备equipment.push_back(newEquipment(金箍棒,1000));equipment.push_back(newEquipment(锁子黄金甲,500));equipment.push_back(newEquipment(凤翅紫静,300));equipment.push_back(newEquipment(藕丝步云履,200));}// 复制构造函数SunWuKong(constSunWuKongother):name(other.name),health(other.health),attack(other.attack),skills(other.skills),equipment(other.equipment){}// 拷贝赋值运算符SunWuKongoperator(constSunWuKongother){if(this!other){nameother.name;healthother.health;attackother.attack;skillsother.skills;equipmentother.equipment;}return*this;}~SunWuKong(){for(autoeq:equipment){deleteeq;}}};// 创建分身voidcreateCloneMonkey(){// 创建本体SunWuKong*originalnewSunWuKong(齐天大圣,1000,100);// 吹毛化兵创建分身vectorSunWuKong*clones;for(inti0;i100000;i){std::count创建第 i 个分身\n;SunWuKong*clonenewSunWuKong(*original);clones.push_back(clone);}deleteoriginal;// 删除分身for(autoclone:clones){deleteclone;}}问题点性能上每次创建分身时都需要初始化技能和装备效率低下灵活性差如果修改了本体分身不会自动进行更新浅拷贝问题容易导致双重释放或访问已释放内存解决方案使用原型模式之后创建原型抽象类classCharacterPrototype{public:virtual~CharacterPrototype(){}default;virtualCharacterPrototype*clone()const0;virtualvoiddisplay()const0;virtualstd::stringgetName()const0;virtualvoidsetName(std::string name)0;};具体原型类classSunWuKong:publicCharacterPrototype{private:std::string name;inthealth;intattack;std::vectorstd::stringskills;std::vectorEquipment*equipment;public:SunWuKong(std::string name,inthealth,intattack):name(name),health(health),attack(attack){// 初始化技能skills.push_back(七十二变);skills.push_back(筋斗云);skills.push_back(火眼金睛);skills.push_back(法天象地);// 初始化装备equipment.push_back(newEquipment(金箍棒,1000));equipment.push_back(newEquipment(锁子黄金甲,500));equipment.push_back(newEquipment(凤翅紫金冠,300));equipment.push_back(newEquipment(藕丝步云履,200));}// 拷贝构造函数(采用深拷贝)SunWuKong(constSunWuKongother){nameother.name;healthother.health;attackother.attack;skillsother.skills;equipment.clear();for(autoeq:other.equipment){equipment.push_back(eq-clone());}}// 拷贝赋值运算符(采用深拷贝)SunWuKongoperator(constSunWuKongother){if(this!other){nameother.name;healthother.health;attackother.attack;skillsother.skills;equipment.clear();for(autoeq:other.equipment){equipment.push_back(eq-clone());}}}// 克隆方法(核心)CharacterPrototype*clone()constoverride{returnnewSunWuKong(*this);// 调用拷贝构造函数}voidsetName(std::string name)override{this-namename;}std::stringgetName()constoverride{returnname;}voiddisplay()constoverride{std::coutname: this-name , health: this-health , attack: this-attack , skills: \n;for(constautoskill:skills){std::coutskill ;}std::cout\n;std::coutequipment:\n;for(constautoeq:equipment){eq-display();}}~SunWuKong(){for(autoeq:equipment){deleteeq;}}};原型管理器classPrototypeManager{private:std::unordered_mapstd::string,CharacterPrototype*prototypes;public:~PrototypeManager(){for(autopair:prototypes){deletepair.second;}}voidaddPrototype(std::string key,CharacterPrototype*prototype){prototypes[key]prototype;}CharacterPrototype*getPrototype(std::string key){if(prototypes.find(key)!prototypes.end()){returnprototypes[key]-clone();}returnnullptr;}};使用voidusePrototype(){// 1. 创建原型SunWukong*originalnewSunWukong(齐天大圣孙悟空,1500,150);original-display();std::cout\n--- 孙悟空吹毫毛变分身 ---\n;// 2. 创建多个分身std::vectorCharacterPrototype*clones;for(inti1;i30;i){// 使用克隆方法创建分身CharacterPrototype*cloneoriginal-clone();clone-setName(孙悟空分身to_string(i));clones.push_back(clone);}// 3. 分身展示for(autoclone:clones){clone-display();}// 4. 清理内存for(autoclone:clones){deleteclone;}deleteoriginal;}voidusePrototypeManager(){PrototypeManager manager;manager.addPrototype(孙悟空,newSunWuKong(齐天大圣孙悟空,1500,150));// 从管理器获取原型并克隆autocloneFromManagermanager.getPrototype(sunwukong);if(cloneFromManager){cloneFromManager-setName(管理器中克隆的分身);cloneFromManager-display();deletecloneFromManager;}}voidcomparison(){autostart1std::chrono::high_resolution_clock::now();// 传统方式创建10000个分身std::vectorSunWuKong*clones1;SunWuKong*originalnewSunWuKong(齐天大圣,1000,100);for(inti0;i10000;i){clones1.push_back(newSunWuKong(分身,1000,100));}autoend1std::chrono::high_resolution_clock::now();autostart2std::chrono::high_resolution_clock::now();// 原型模式创建10000个分身std::vectorCharacterPrototype*clones2;for(inti0;i10000;i){clones2.push_back(original-clone());}autoend2std::chrono::high_resolution_clock::now();std::cout传统方式耗时: std::chrono::duration_caststd::chrono::milliseconds(end1-start1).count()ms\n;std::cout原型模式耗时: std::chrono::duration_caststd::chrono::milliseconds(end2-start2).count()ms\n;}附上UML图:二、总结2.1、与传统方式进行对比特点传统创建方式原型模式性能低每次都要执行完整初始化高一次初始化多次复制内存每个对象独立内存可共享不变部分代码复杂度低高需要实现clone灵活性低高可动态修改原型适用场景对象创建简单对象创建复杂,批量创建2.2、深拷贝 VS 浅拷贝浅拷贝:亦可称为值拷贝。将源对象的值拷贝到目标对象中如果对象中某个成员是指针类型数据并且是在堆上创建的那么源对象和目标对象都指向同一块内存区域此时如果其中一个对象释放了内存那么另一个对象的指针就会变成野指针。深拷贝在拷贝的时候先开辟出与源对象大小一样的空间然后将源对象的内容拷贝到新开辟的空间中。这样无论哪个对象释放内存都不会影响另一个对象的正常使用。2.3、原型模式 VS 工厂模式原型模式通过克隆原型对象来创建新的对象适用于创建复杂对象特别是当对象的创建过程较为耗时或复杂时。工厂模式通过工厂方法来创建对象适用于创建不同类型的对象特别是当对象的创建逻辑较为复杂时。三、附加由于C语法的灵活性原型模式实现可以有多种方式1. 结合智能指针版–原型模式// 使用智能指针和移动语义classSunWuKong1:publicCharacterPrototype{private:string name;inthealth;intattack;vectorstringskills;vectorunique_ptrEquipmentequipment;// 使用unique_ptrpublic:SunWuKong1(string name,inthealth,intattack):name(name),health(health),attack(attack){// 初始化技能skills.push_back(七十二变);skills.push_back(筋斗云);skills.push_back(火眼金睛);skills.push_back(法天象地);// 初始化装备equipment.push_back(newEquipment(金箍棒,1000));equipment.push_back(newEquipment(锁子黄金甲,500));equipment.push_back(newEquipment(凤翅紫金冠,300));equipment.push_back(newEquipment(藕丝步云履,200));}// 使用移动构造函数提高效率SunWuKong1(SunWuKong1other)noexcept:name(move(other.name)),health(other.health),attack(other.attack),skills(move(other.skills)),equipment(move(other.equipment)){}CharacterPrototype*clone()constoverride{// 先创建一个副本autoclonemake_uniqueSunWuKong1(name,health,attack);// 深拷贝equipmentfor(constautoeq:equipment){clone-equipment.push_back(make_uniqueEquipment(*eq));}returnclone.release();}};2. 结合函数模板通过注册的方式–原型模式classPrototypeRegistry{private:staticunordered_mapstring,functionunique_ptrCharacterPrototype()registry;public:staticvoidregisterPrototype(conststringkey,functionunique_ptrCharacterPrototype()creator){registry[key]move(creator);}staticunique_ptrCharacterPrototypeclone(conststringkey){if(autoitregistry.find(key);it!registry.end()){returnit-second();}returnnullptr;}};
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

公司网站模板内容军事新闻头条最新军情

11月22日-25日,由创客匠人主办的 “全球创始人IPAI万人高峰论坛” 在厦门海峡大剧院圆满落幕。峰会首日,备受瞩目的 “AI应用前景圆桌论坛” 汇聚多位行业领袖,围绕 “AI如何重构IP价值、赋能企业增长” 展开深度探讨,为现场万名创…

张小明 2026/1/2 12:54:12 网站建设

网站备案多少天旅游网站功能简介

第一章:Open-AutoGLM调试实战概述 在大语言模型快速发展的背景下,Open-AutoGLM作为一款支持自动化推理与任务生成的开源框架,为开发者提供了灵活的调试接口和模块化设计。本章聚焦于实际开发中常见的调试场景,帮助用户快速定位问题…

张小明 2026/1/3 1:37:10 网站建设

网络营销市场外贸网站自我建设与优化

CountUp.js数字动画库:从零到精通的终极指南 【免费下载链接】countUp.js Animates a numerical value by counting to it 项目地址: https://gitcode.com/gh_mirrors/co/countUp.js CountUp.js是一款零依赖、轻量级的JavaScript数字动画工具库,专…

张小明 2026/1/8 8:39:54 网站建设

怎样看一个网站是哪个公司做的高端网站设计公司排行榜

第一章:Agent 工具的 Dify 测试用例 在构建基于 Agent 的智能系统时,Dify 作为一个低代码 AI 应用开发平台,提供了强大的工具链支持测试用例的设计与执行。通过其可视化编排界面和开放 API,开发者能够快速定义输入输出行为&#x…

张小明 2026/1/8 7:59:14 网站建设

新浪云 建设网站科技最狂潮

rembg Python 3.13迁移实战:5大常见问题排雷指南 【免费下载链接】rembg Rembg is a tool to remove images background 项目地址: https://gitcode.com/GitHub_Trending/re/rembg 还在为Python版本升级导致rembg背景移除工具失效而头疼吗?今天我…

张小明 2026/1/3 22:39:04 网站建设

想建设一个网站有哪些做的好的小众网站

第一章:智谱Open-AutoGLM PC版核心功能概览智谱Open-AutoGLM PC版是一款面向本地化部署的大模型推理与自动化任务处理工具,专为开发者和企业用户设计,支持离线运行、高效调度与多场景适配。该平台融合了自然语言理解、代码生成、数据处理与工…

张小明 2025/12/28 22:06:13 网站建设