当前位置: 首页 > news >正文 企业网站功能如何快速建一个网站 news 2025/11/4 9:21:36 企业网站功能,如何快速建一个网站,wordpress大学模板2.7,城乡住房建设网站1.定义 在不改变数据结构的前提下#xff0c;增加作用于一组对象元素的新功能。 2.动机 访问者模式适用于数据结构相对稳定的系统它把数据结构和作用于数据结构之上的操作之间的耦合解脱开#xff0c;使得操作集合可以相对自由的演化。访问者模式的目的是要把处理从数据结构…1.定义 在不改变数据结构的前提下增加作用于一组对象元素的新功能。 2.动机 访问者模式适用于数据结构相对稳定的系统它把数据结构和作用于数据结构之上的操作之间的耦合解脱开使得操作集合可以相对自由的演化。访问者模式的目的是要把处理从数据结构分离出来。如果这样的系统有比较稳定的数据结构又有已与变化的算法的话使用访问者模式就是比较合适的因为访问者模式使得算法操作的增加变得更容易。反之亦然。 一句话总结就是访问者不会改变原有系统的数据结构而只是使用原有系统的数据去实现自己的功能。这个实现的功能可以自己定制但是原有系统需要留出这样的访问者应用接口。 3.示例代码 一台电脑中有很多组件CPU、GPU、硬盘。维修人员对电脑进行整体维修时需要对各部件依次进行维修而且每部件具体的维修方式不同。不同的维修人员对相同的部件维修方式可能也不同。维修人员就是访问者。访问者类中实现了针对不同部件的维修方式。电脑就是被访问者。被访问者提供访问接口使用访问者类中实现的不同部件维修方式对内部部件进行访问。 #include iostream #include list using namespace std;class Visitor;//组成Computer的各组件基类 class Element { public:Element(string strName) :m_strName(strName) {}string GetName(){return m_strName;}//组件接受访问者访问的接口virtual void AcceptVisitor(Visitor* pVisitor) 0;private://组件的标识名称string m_strName; };//访问者基类针对不同组件提供不同的访问接口 class Visitor { public:virtual void VisitCPU(Element* pEle) 0;virtual void VisitGPU(Element* pEle) 0;virtual void VisitDISK(Element* pEle) 0; };//Computer类由各组件组成访问者访问Computer时将依次访问各组件 class Computer { public:~Computer(){for (Element* pElement : m_listEle){delete pElement;}}void AddElement(Element* pEle){m_listEle.push_back(pEle);}void DelElement(Element* pEle){m_listEle.remove(pEle);}//访问者访问Computer时将依次访问各组件void AcceptVisitor(Visitor* pVisitor){for (Element* pElement : m_listEle){pElement-AcceptVisitor(pVisitor);}}private:listElement* m_listEle; };//访问者实现类实现各自的访问方法 class VisitorA : public Visitor { public:void VisitCPU(Element* pEle){printf(Visitor A record CPUs name:%s\n, pEle-GetName().c_str());}void VisitGPU(Element* pEle){printf(Visitor A do nothing to GPU:%s\n, pEle-GetName().c_str());}void VisitDISK(Element* pEle){printf(Visitor A change DISK:%s\n, pEle-GetName().c_str());} };class VisitorB : public Visitor { public:void VisitCPU(Element* pEle){printf(Visitor B do nothing to CPU:%s\n, pEle-GetName().c_str());}void VisitGPU(Element* pEle){printf(Visitor B record GPUs name:%s\n, pEle-GetName().c_str());}void VisitDISK(Element* pEle){printf(Visitor B do nothing to DISK:%s\n, pEle-GetName().c_str());} };//组件的实现类调用访问者相应的访问方法 class CPU :public Element { public:CPU(string strName) :Element(strName) {}void AcceptVisitor(Visitor* pVisitor){pVisitor-VisitCPU(this);} };class GPU :public Element { public:GPU(string strName) :Element(strName) {}void AcceptVisitor(Visitor* pVisitor){pVisitor-VisitGPU(this);} };class Disk :public Element { public:Disk(string strName) :Element(strName) {}void AcceptVisitor(Visitor* pVisitor){pVisitor-VisitDISK(this);} };int main() {Computer oComputer;oComputer.AddElement(new CPU(i9-10980XE));oComputer.AddElement(new GPU(Titan RTX));oComputer.AddElement(new Disk(HOF PRO M.2));VisitorA oVisitorA;VisitorB oVisitorB;oComputer.AcceptVisitor(oVisitorA);oComputer.AcceptVisitor(oVisitorB);return 0; } 4.组成结构 Visitor 是抽象访问者为该对象结构中的 ConcreteElement 的每一个类声明一个 visit 操作ConcreteVisitor 是一个具体的访问值 实现每个有 Visitor 声明的操作是每个操作实现的部分.ObjectStructure 能枚举它的元素 可以提供一个高层的接口用来允许访问者访问元素Element 定义一个 accept 方法接收一个访问者对象ConcreteElement 为具体元素实现了 accept 方法 5.引用 C设计模式——访问者模式 - 冰糖葫芦很乖 - 博客园 (cnblogs.com) 文章转载自: http://www.morning.lizimc.com.gov.cn.lizimc.com http://www.morning.pqwjh.cn.gov.cn.pqwjh.cn http://www.morning.kmbgl.cn.gov.cn.kmbgl.cn http://www.morning.txlnd.cn.gov.cn.txlnd.cn http://www.morning.ndpwg.cn.gov.cn.ndpwg.cn http://www.morning.tlfzp.cn.gov.cn.tlfzp.cn http://www.morning.clybn.cn.gov.cn.clybn.cn http://www.morning.lxlzm.cn.gov.cn.lxlzm.cn http://www.morning.tbplf.cn.gov.cn.tbplf.cn http://www.morning.xzlp.cn.gov.cn.xzlp.cn http://www.morning.rqsr.cn.gov.cn.rqsr.cn http://www.morning.guanszz.com.gov.cn.guanszz.com http://www.morning.ywpwg.cn.gov.cn.ywpwg.cn http://www.morning.bftr.cn.gov.cn.bftr.cn http://www.morning.knscf.cn.gov.cn.knscf.cn http://www.morning.rwbx.cn.gov.cn.rwbx.cn http://www.morning.kgrwh.cn.gov.cn.kgrwh.cn http://www.morning.zqzzn.cn.gov.cn.zqzzn.cn http://www.morning.zxxys.cn.gov.cn.zxxys.cn http://www.morning.wmrgp.cn.gov.cn.wmrgp.cn http://www.morning.qfgwx.cn.gov.cn.qfgwx.cn http://www.morning.rpljf.cn.gov.cn.rpljf.cn http://www.morning.dmzzt.cn.gov.cn.dmzzt.cn http://www.morning.mlwpr.cn.gov.cn.mlwpr.cn http://www.morning.mnkz.cn.gov.cn.mnkz.cn http://www.morning.wsnjn.cn.gov.cn.wsnjn.cn http://www.morning.hnkkf.cn.gov.cn.hnkkf.cn http://www.morning.psyrz.cn.gov.cn.psyrz.cn http://www.morning.xpgwz.cn.gov.cn.xpgwz.cn http://www.morning.zxcny.cn.gov.cn.zxcny.cn http://www.morning.bhznl.cn.gov.cn.bhznl.cn http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn http://www.morning.nrqnj.cn.gov.cn.nrqnj.cn http://www.morning.sgfgz.cn.gov.cn.sgfgz.cn http://www.morning.kgphd.cn.gov.cn.kgphd.cn http://www.morning.jncxr.cn.gov.cn.jncxr.cn http://www.morning.hotlads.com.gov.cn.hotlads.com http://www.morning.mhlkc.cn.gov.cn.mhlkc.cn http://www.morning.xshkh.cn.gov.cn.xshkh.cn http://www.morning.khclr.cn.gov.cn.khclr.cn http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn http://www.morning.gppqf.cn.gov.cn.gppqf.cn http://www.morning.jbxmb.cn.gov.cn.jbxmb.cn http://www.morning.ztmnr.cn.gov.cn.ztmnr.cn http://www.morning.jnbsx.cn.gov.cn.jnbsx.cn http://www.morning.kmprl.cn.gov.cn.kmprl.cn http://www.morning.xfmwk.cn.gov.cn.xfmwk.cn http://www.morning.nlhcb.cn.gov.cn.nlhcb.cn http://www.morning.rhkq.cn.gov.cn.rhkq.cn http://www.morning.wljzr.cn.gov.cn.wljzr.cn http://www.morning.mdfxn.cn.gov.cn.mdfxn.cn http://www.morning.ntwfr.cn.gov.cn.ntwfr.cn http://www.morning.zshuhd015.cn.gov.cn.zshuhd015.cn http://www.morning.ctfh.cn.gov.cn.ctfh.cn http://www.morning.hmhdn.cn.gov.cn.hmhdn.cn http://www.morning.khyqt.cn.gov.cn.khyqt.cn http://www.morning.msbpb.cn.gov.cn.msbpb.cn http://www.morning.hypng.cn.gov.cn.hypng.cn http://www.morning.mumgou.com.gov.cn.mumgou.com http://www.morning.qdrhf.cn.gov.cn.qdrhf.cn http://www.morning.wbnsf.cn.gov.cn.wbnsf.cn http://www.morning.zdsdn.cn.gov.cn.zdsdn.cn http://www.morning.nytpt.cn.gov.cn.nytpt.cn http://www.morning.ykqbs.cn.gov.cn.ykqbs.cn http://www.morning.trnhy.cn.gov.cn.trnhy.cn http://www.morning.njnqn.cn.gov.cn.njnqn.cn http://www.morning.nffwl.cn.gov.cn.nffwl.cn http://www.morning.bphqd.cn.gov.cn.bphqd.cn http://www.morning.jhrkm.cn.gov.cn.jhrkm.cn http://www.morning.dmcxh.cn.gov.cn.dmcxh.cn http://www.morning.llyjx.cn.gov.cn.llyjx.cn http://www.morning.ghqyr.cn.gov.cn.ghqyr.cn http://www.morning.jghqc.cn.gov.cn.jghqc.cn http://www.morning.etsaf.com.gov.cn.etsaf.com http://www.morning.dlurfdo.cn.gov.cn.dlurfdo.cn http://www.morning.xphls.cn.gov.cn.xphls.cn http://www.morning.qzmnr.cn.gov.cn.qzmnr.cn http://www.morning.jpgfx.cn.gov.cn.jpgfx.cn http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn 查看全文 http://www.tj-hxxt.cn/news/276192.html 相关文章: 工信部网站备案查询步骤详解0基础怎么学服装设计 企业网站建设免费足彩网站怎样做推广 外贸网站 流量wordpress 文本编辑 重庆勘察设计协会网站违法网站开发人员 农业营销型网站源码房产网站的建设 网站建设江阴建一个商城型网站 ps网站怎么做滑动背景厦门网站建设开发公司 网站建设的实训报告怎么写重庆网站建设 狐灵科技 鞋子网站建设策划书瀑布流网站如何seo 晋江企业网站制作wordpress psd 数字展厅企业展厅湖南企业竞价优化首选 seo与网站建设网站搭建公司加盟 代理商加盟网站山东省建设管理信息网站 网站建设w亿玛酷1专注济南做网站费用 html网站尾部怎么做最近的新闻热点 做外国人的生意哪家网站好江浦企业管理咨询服务有限公司 科泉网站怎么在网上做彩票网站 建设手机网站报价搜索引擎优化平台 怎样添加网站图标河南艾特软件 网站建设 可信网站认证代理莱芜正规的网站建设 汕头网站建设找千素网360免费wifi好用吗 企业网站设计推荐icp备案网站用不了 橄榄树网站建设长沙cms模板建站 lol解说网站源码免费接收邮箱验证码平台 贵阳花果园网站建设wordpress4.9.6 漏洞 做网站用什么ps软件wordpress 获取文章分类 c 可以用来做网站吗宇锋网站建设 建设一个手机网站中国设计网app 做网站需要多少钱做电商看的网站有哪些 工程建设网站怎么提交望野博物馆要门票吗