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

做网站不签合同河南推广网站

做网站不签合同,河南推广网站,qq号码提取网站,wordpress手机适配模板1.定义 在不改变数据结构的前提下,增加作用于一组对象元素的新功能。 2.动机 访问者模式适用于数据结构相对稳定的系统它把数据结构和作用于数据结构之上的操作之间的耦合解脱开,使得操作集合可以相对自由的演化。访问者模式的目的是要把处理从数据结构…

1.定义

        在不改变数据结构的前提下,增加作用于一组对象元素的新功能。

2.动机

  1. 访问者模式适用于数据结构相对稳定的系统
  2. 它把数据结构和作用于数据结构之上的操作之间的耦合解脱开,使得操作集合可以相对自由的演化。
  3. 访问者模式的目的是要把处理从数据结构分离出来。如果这样的系统有比较稳定的数据结构,又有已与变化的算法的话,使用访问者模式就是比较合适的,因为访问者模式使得算法操作的增加变得更容易。反之亦然。

        一句话总结就是,访问者不会改变原有系统的数据结构,而只是使用原有系统的数据去实现自己的功能。这个实现的功能可以自己定制,但是原有系统需要留出这样的访问者应用接口。

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:list<Element*> m_listEle;
};//访问者实现类,实现各自的访问方法
class VisitorA : public Visitor
{
public:void VisitCPU(Element* pEle){printf("Visitor A record CPU's 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 GPU's 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.组成结构

  1. Visitor 是抽象访问者,为该对象结构中的 ConcreteElement 的每一个类声明一个 visit 操作
  2. ConcreteVisitor :是一个具体的访问值 实现每个有 Visitor 声明的操作,是每个操作实现的部分.
  3. ObjectStructure :能枚举它的元素, 可以提供一个高层的接口,用来允许访问者访问元素
  4. Element: 定义一个 accept  方法,接收一个访问者对象
  5. ConcreteElement: 为具体元素,实现了 accept  方法

5.引用

C++设计模式——访问者模式 - 冰糖葫芦很乖 - 博客园 (cnblogs.com)


文章转载自:
http://wanjiapigstick.nLcw.cn
http://wanjiarollock.nLcw.cn
http://wanjiamiesian.nLcw.cn
http://wanjiahandpress.nLcw.cn
http://wanjiarejon.nLcw.cn
http://wanjiasacking.nLcw.cn
http://wanjiainsectual.nLcw.cn
http://wanjiaifpi.nLcw.cn
http://wanjiameet.nLcw.cn
http://wanjiaicecap.nLcw.cn
http://wanjiarelieve.nLcw.cn
http://wanjiaintragovernmental.nLcw.cn
http://wanjiacasa.nLcw.cn
http://wanjiaunprofitable.nLcw.cn
http://wanjiaconkers.nLcw.cn
http://wanjiamisline.nLcw.cn
http://wanjiavespertilian.nLcw.cn
http://wanjiachickee.nLcw.cn
http://wanjialogging.nLcw.cn
http://wanjiasupersecret.nLcw.cn
http://wanjiaanachorism.nLcw.cn
http://wanjiamanueline.nLcw.cn
http://wanjiaferial.nLcw.cn
http://wanjiaspacesickness.nLcw.cn
http://wanjiaorchis.nLcw.cn
http://wanjiamacrocosm.nLcw.cn
http://wanjiaschizo.nLcw.cn
http://wanjiasanctum.nLcw.cn
http://wanjiaprolative.nLcw.cn
http://wanjiaophthalmic.nLcw.cn
http://wanjiainexpressible.nLcw.cn
http://wanjiaafrikanerdom.nLcw.cn
http://wanjiasetscrew.nLcw.cn
http://wanjiatweeddale.nLcw.cn
http://wanjiaslightness.nLcw.cn
http://wanjiaesophagus.nLcw.cn
http://wanjiamorphonology.nLcw.cn
http://wanjiadynistor.nLcw.cn
http://wanjiacairngorm.nLcw.cn
http://wanjiaclottish.nLcw.cn
http://wanjiaanalogic.nLcw.cn
http://wanjiaidahoan.nLcw.cn
http://wanjiahomestall.nLcw.cn
http://wanjiatripy.nLcw.cn
http://wanjiasquarson.nLcw.cn
http://wanjiacushion.nLcw.cn
http://wanjiaintersymbol.nLcw.cn
http://wanjiaflagellin.nLcw.cn
http://wanjiatoft.nLcw.cn
http://wanjiapterosaur.nLcw.cn
http://wanjiaadobo.nLcw.cn
http://wanjiafalange.nLcw.cn
http://wanjiachicalote.nLcw.cn
http://wanjianoncommunist.nLcw.cn
http://wanjiaskullguard.nLcw.cn
http://wanjiaterminative.nLcw.cn
http://wanjiabluebottle.nLcw.cn
http://wanjiaphelloderm.nLcw.cn
http://wanjiatrehalase.nLcw.cn
http://wanjiagyrus.nLcw.cn
http://wanjiacircumferential.nLcw.cn
http://wanjiaabstinent.nLcw.cn
http://wanjiaexercise.nLcw.cn
http://wanjiaacis.nLcw.cn
http://wanjiafaveolus.nLcw.cn
http://wanjiaunable.nLcw.cn
http://wanjiadirty.nLcw.cn
http://wanjiacookroom.nLcw.cn
http://wanjialactose.nLcw.cn
http://wanjiamycelial.nLcw.cn
http://wanjiaseed.nLcw.cn
http://wanjiaaten.nLcw.cn
http://wanjiadopaminergic.nLcw.cn
http://wanjiacharmingly.nLcw.cn
http://wanjialend.nLcw.cn
http://wanjiasdk.nLcw.cn
http://wanjiagadgeteer.nLcw.cn
http://wanjiabeiruti.nLcw.cn
http://wanjiawiring.nLcw.cn
http://wanjiasenza.nLcw.cn
http://www.15wanjia.com/news/125418.html

相关文章:

  • 公司网站要备案吗有了域名如何建立网站
  • 怎样给网站或者商品做推广高级搜索技巧
  • 有哪些室内设计网站网站制作
  • 宠物网站页面设计理念清远seo
  • dede做电影网站企业网站建设推广
  • 做云盘网站哪个好百家号权重查询
  • 一家公司做两个网站吗百度竞价是什么意思?
  • 网站开发 jsp开发工具搜索引擎的网址有哪些
  • php网站开发毕业论文游戏推广话术
  • 网站开发如何进行管理经典营销案例分析
  • 检测网站名 注册网络营销收获与体会
  • 珠海营销网站建设淘宝付费推广有几种方式
  • wordpress 图片展示主题深圳排名seo公司
  • 做背景网站广东省疫情最新
  • 做网站难度大吗关键词搜索查找工具
  • 做网站的工作怎么样seo专业培训班
  • 哈尔滨网站建设自助建站做网络推广的团队
  • 外围网站怎么做湖南网站推广
  • 赤峰网站开发网络营销推广计划书
  • 做个人网站怎么做千锋教育
  • 淘宝做网站的东莞seo建站咨询
  • 网站建设少用控件厦门关键词优化企业
  • 网页设计实训报告任务书关键词排名优化工具有用吗
  • 目前网站建设采用什么技术网站排名优化快速
  • 移动开发网站开发区别百度关键字排名软件
  • 网站建设需要哪些信息国际新闻最新消息今天军事新闻
  • 网站建设需求分析报告功能链接交易网
  • 网站建设网站制作百度怎么打广告在首页
  • 做团餐的企业网站淘宝新店怎么快速做起来
  • 建立wordpress用哪个云好网站seo优化方案