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

赶集网做网站站长工具app下载

赶集网做网站,站长工具app下载,有哪些好的印花图案设计网站,猎头公司前十名有哪些意图:将对象组成树状结构以表示“部分-整体”的层次结构,使得Client对单个对象和组合对象的使用具有一致性。 上下文:在树型结构的问题中,Client必须以不同的方式处理单个对象和组合对象。能否提供一种封装&#xff0c…

意图:将对象组成树状结构以表示“部分-整体”的层次结构,使得Client对单个对象和组合对象的使用具有一致性。

上下文:在树型结构的问题中,Client必须以不同的方式处理单个对象和组合对象。能否提供一种封装,统一简单元素和复杂元素的概念,让对象容器自己来实现自身的复杂结构,让Client可以像处理简单元素一样来处理复杂元素,从而使Client与复杂元素的内部结构解耦?

UML

在这里插入图片描述

Component:为Composite中的对象声明接口;在适当情况下,实现所有类公共接口的默认行为;声明一个接口,用于访问和管理Component的子部件;在递归结构中定义一个接口,用于访问一个父部件,并在适当的情况下实现它。
Leaf:在Composite中表示叶子对象。
Composite:存储子部件,并定义有子部件的那些部件的行为。
Client:通过Component接口操作Composite的对象。

在这里插入图片描述

代码:

#include <iostream>
#include <list>
using namespace std;class Component
{
public:string name;Component(string name):name(name){}virtual void add(Component *c) = 0;virtual void remove(Component *c) = 0;virtual void display(int depth) = 0;
};class Leaf:public Component
{
public:// Component interfaceLeaf(string name):Component(name){}
public:void add(Component *c);void remove(Component *c);void display(int depth);
};void Leaf::add(Component *c )
{(void)(c);//消除警告cout << "不能向叶子中添加Component" << endl;
}void Leaf::remove(Component *c)
{(void)(c);//Warningcout << "不能从叶子中删除Component" << endl;
}void Leaf::display(int depth)
{cout << string(depth,'-') << this->name << endl;
}class Composite:public Component
{
public:list<Component*> children;// Component interfaceComposite(string name):Component(name){}
public:void add(Component *c);void remove(Component *c);void display(int depth);
};
void Composite::add(Component *c)
{children.push_back(c);
}void Composite::remove(Component *c)
{children.remove(c);
}void Composite::display(int depth)
{cout << string(depth,'-') << this->name << endl;list<Component*>::iterator it;for(it = children.begin();it != children.end();it++){Component *c = *it;c->display(depth + 2);}
}
int main()
{Composite *root = new Composite("树干");root->add(new Leaf("树叶1"));root->add(new Leaf("树叶2"));Composite *c1 = new Composite("树枝1");c1->add(new Leaf("树叶1-1"));c1->add(new Leaf("树叶1-2"));root->add(c1);Composite *c1_1 = new Composite("树枝1-1");c1_1->add(new Leaf("树叶1-1-1"));c1_1->add(new Leaf("树叶1-1-2"));c1->add(c1_1);root->add(new Leaf("树叶3"));root->display(1);return 0;
}

结果

-树干
---树叶1
---树叶2
---树枝1
-----树叶1-1
-----树叶1-2
-----树枝1-1
-------树叶1-1-1
-------树叶1-1-2
---树叶3
http://www.khdw.cn/news/37127.html

相关文章:

  • wordpress如何卸载网络推广优化
  • 成都网站建设cdxwcx网络营销seo培训
  • dreamweaver软件是做什么的百度关键词快速优化
  • 成都网站建设工作室aso优化技术
  • asp服装网站模板平台推广是做什么的
  • 成都企业网站建设网页广告调词平台
  • 网站目录是什么百度快照如何优化
  • 做网站注意什么qq群引流推广平台免费
  • 绍兴公司企业名单seo优化培训机构
  • 胶州哪家公司做网站交换链接营销的典型案例
  • 网站营销看法平台推广方式有哪些
  • 工程信息建程网青岛seo
  • 内蒙古地区做推广网站自媒体seo是什么意思
  • 高端建站价格友情链接出售
  • 中国建设银行嵊州市支行网站厦门seo关键词优化
  • 英文站 wordpress培训心得体会范文500字
  • dw手机销售网站制作百度推广怎么样才有效果
  • 郑州交友网站建设网站优化公司哪家效果好
  • 网站建设费用标准对网站和网页的认识
  • 叮当设计官网武汉网络推广seo
  • 网站开发毕设论文百度移动应用
  • 电子商务网站开发方案香港域名注册网站
  • 做柜子喜欢上哪些网站看企业网站营销
  • 帮别人做网站需要什么能力crm系统网站
  • 高密做网站的公司做网站找哪个公司好
  • 自己做微信优惠券需要网站企业网站类型有哪些
  • html搭建网站做推广网络
  • wordpress 音乐播放器 歌词seo自然排名关键词来源的优缺点
  • 女与男爱做电影网站免费百度一下官方网址
  • 做地接的网站什么是软文文案