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

现在网站优化n127网推广

现在网站优化,n127网推广,php 开源 建站,wordpress开源博客意图:将对象组成树状结构以表示“部分-整体”的层次结构,使得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.hkea.cn/news/487044/

相关文章:

  • 太原市建设交易中心网站首页百度手机助手app安卓版官方下载
  • 昆山网站建设网站建设郑州网络推广哪个好
  • 瑜伽网站设计国外推广网站
  • 什么网站做国外批发百度推广自己怎么做
  • 网站管理工具百度推广可以自己开户吗
  • 三水网站制作中山做网站推广公司
  • ysl网站设计论文郑州seo地址
  • 做食品的网站设计要注意片多多可以免费看电视剧吗
  • 网站排名推广自己怎么做长沙seo代理商
  • 手机网站改版公司加盟关键词优化排名查询
  • html5 图片网站建设企业网站多少钱
  • 企业网站定制开发流程网络营销的概念及特点
  • 做火影网站背景图农村电商平台有哪些
  • 国内html5网站建设seo兼职工资一般多少
  • 青海西宁网站建设公司百度网络推广
  • 服装公司网站设计百度站长收录入口
  • 做搜索关键词任务网站网站维护是什么意思
  • 2018什么做网站百度网盘网页版入口
  • 深圳福田大型商城网站建设石家庄最新疫情最新消息
  • 网站版面结构chatgpt 网站
  • 网站后期推广是谁来做广州百度推广开户
  • 不上此网站枉做男人免费制作网站平台
  • 防红短链接生成佛山抖音seo
  • 网站建设php带数据库模板站长工具四叶草
  • 做网站客户拖着不验收店铺推广渠道有哪些方式
  • 站群系统哪个好用怎样进行seo推广
  • 淄博网站建设方案网络推广是做什么的
  • 网站建设销售工作职责seo平台怎么样
  • 免费的网站给一个百度seo优化服务项目
  • 现代广告创意设计郑州百度网站优化排名