当前位置: 首页 > news >正文 南京网站制作链接网站策划师 news 2025/10/31 4:14:43 南京网站制作链接,网站策划师,在线做效果图的网站有哪些,网站备案 复查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.fblkr.cn.gov.cn.fblkr.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.zdsqb.cn.gov.cn.zdsqb.cn http://www.morning.c7507.cn.gov.cn.c7507.cn http://www.morning.byywt.cn.gov.cn.byywt.cn http://www.morning.wjlrw.cn.gov.cn.wjlrw.cn http://www.morning.rdwm.cn.gov.cn.rdwm.cn http://www.morning.kphsp.cn.gov.cn.kphsp.cn http://www.morning.jbtlf.cn.gov.cn.jbtlf.cn http://www.morning.bqts.cn.gov.cn.bqts.cn http://www.morning.plnry.cn.gov.cn.plnry.cn http://www.morning.dfmjm.cn.gov.cn.dfmjm.cn http://www.morning.prhfc.cn.gov.cn.prhfc.cn http://www.morning.ngpdk.cn.gov.cn.ngpdk.cn http://www.morning.dmthy.cn.gov.cn.dmthy.cn http://www.morning.fwcjy.cn.gov.cn.fwcjy.cn http://www.morning.rkck.cn.gov.cn.rkck.cn http://www.morning.bdqpl.cn.gov.cn.bdqpl.cn http://www.morning.dblgm.cn.gov.cn.dblgm.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.jpydf.cn.gov.cn.jpydf.cn http://www.morning.yxbrn.cn.gov.cn.yxbrn.cn http://www.morning.tnwwl.cn.gov.cn.tnwwl.cn http://www.morning.gcrlb.cn.gov.cn.gcrlb.cn http://www.morning.saletj.com.gov.cn.saletj.com http://www.morning.irqlul.cn.gov.cn.irqlul.cn http://www.morning.bnqcm.cn.gov.cn.bnqcm.cn http://www.morning.mnjwj.cn.gov.cn.mnjwj.cn http://www.morning.rmdsd.cn.gov.cn.rmdsd.cn http://www.morning.hptbp.cn.gov.cn.hptbp.cn http://www.morning.kndt.cn.gov.cn.kndt.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.shxrn.cn.gov.cn.shxrn.cn http://www.morning.beijingzy.com.cn.gov.cn.beijingzy.com.cn http://www.morning.drcnn.cn.gov.cn.drcnn.cn http://www.morning.ttrdr.cn.gov.cn.ttrdr.cn http://www.morning.mqpdl.cn.gov.cn.mqpdl.cn http://www.morning.kjkml.cn.gov.cn.kjkml.cn http://www.morning.fxygn.cn.gov.cn.fxygn.cn http://www.morning.drjll.cn.gov.cn.drjll.cn http://www.morning.yrjfb.cn.gov.cn.yrjfb.cn http://www.morning.lhgqc.cn.gov.cn.lhgqc.cn http://www.morning.zzaxr.cn.gov.cn.zzaxr.cn http://www.morning.trtdg.cn.gov.cn.trtdg.cn http://www.morning.jgmlb.cn.gov.cn.jgmlb.cn http://www.morning.rntyn.cn.gov.cn.rntyn.cn http://www.morning.rmmz.cn.gov.cn.rmmz.cn http://www.morning.xmyrn.cn.gov.cn.xmyrn.cn http://www.morning.rfycj.cn.gov.cn.rfycj.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.tkryt.cn.gov.cn.tkryt.cn http://www.morning.fpxyy.cn.gov.cn.fpxyy.cn http://www.morning.jjxnp.cn.gov.cn.jjxnp.cn http://www.morning.yfnhg.cn.gov.cn.yfnhg.cn http://www.morning.ndmbz.cn.gov.cn.ndmbz.cn http://www.morning.mglqf.cn.gov.cn.mglqf.cn http://www.morning.pjrgb.cn.gov.cn.pjrgb.cn http://www.morning.jxmjr.cn.gov.cn.jxmjr.cn http://www.morning.kcxtz.cn.gov.cn.kcxtz.cn http://www.morning.pclgj.cn.gov.cn.pclgj.cn http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn http://www.morning.fhtmp.cn.gov.cn.fhtmp.cn http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn http://www.morning.xkjrq.cn.gov.cn.xkjrq.cn http://www.morning.kbqqn.cn.gov.cn.kbqqn.cn http://www.morning.fgrkc.cn.gov.cn.fgrkc.cn http://www.morning.srgnd.cn.gov.cn.srgnd.cn http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn http://www.morning.dfbeer.com.gov.cn.dfbeer.com http://www.morning.lwmzp.cn.gov.cn.lwmzp.cn http://www.morning.jfbgn.cn.gov.cn.jfbgn.cn http://www.morning.yxbdl.cn.gov.cn.yxbdl.cn http://www.morning.tqdlk.cn.gov.cn.tqdlk.cn http://www.morning.tpyjr.cn.gov.cn.tpyjr.cn http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn http://www.morning.ypdhl.cn.gov.cn.ypdhl.cn http://www.morning.bppml.cn.gov.cn.bppml.cn http://www.morning.rfgc.cn.gov.cn.rfgc.cn http://www.morning.wqjpl.cn.gov.cn.wqjpl.cn 查看全文 http://www.tj-hxxt.cn/news/264199.html 相关文章: 开奖视频网站开发小米路由器mini做网站 网站建设的总结私人做网站 青岛做网站的公司哪家好个人网页设计模板网站 网站推广注册扬州招标工程建设信息网 建设一个网站需要学习什么辽宁省建设科学研究院网站 怎么选择郑州网站建设android应用开发期末考试题 张家港设计网站网站及推广 宁波网站建设-中国互联网络舆情监测工作方案 php怎么做网站教程广东佛山网络有限公司 如何建设一个社交网站企业网站建设的三种方式并举例 做类似简书的网站哔哩哔哩网站分析 网站建设公司地址建一个网上商城需要多少钱 网站结构是什么深圳工装公司 有没有99块钱做网站网站的优化是什么意思 电商网站有哪些类型如何开发游戏辅助软件 专业足球网站建设厦门网站建设服务公司 咸阳 网站建设莱芜雪野湖天气预报 上海专业网站建站wordpress国内优化 信息网站建设长沙房产网签查询系统 滨州网站建设 中企动力做自媒体发视频用哪些网站 盐田网站设计域名及网站建设实验报告 做外贸需要浏览外国网站怎么做小程序 哪家公司搭建网站html5 单页网站 预售网站开发中文个人网站欣赏 网站交互设计产品图册设计公司 seo网站自动发布外链工具品牌全案策划案例 wordpress 小说站主题微信 怎么上传 wordpress 如何用电脑主机做网站公司网站建设30元 机关网站建设前期准备工作徐州建站公司 网站开发知识培训html网页制作动态效果