组合模式(Composite)
2023-04-18 15:02:38 时间
2015/4/28
组合模式(Composite):
将所有对象组织在一个树状结构之下,用来实现对象间部分—整体之间的关系,使得用户对单个对象和组合对象的使用具有一致性。
#include <list>
#include <iostream>
#include <string>
using namespace std;
class Component{
protected:
string name;
public:
virtual void Add(Component *file)=0;
virtual void Remove(Component *file)=0;
virtual list <Component *>* Get()=0;
};
class Leaf:public Component{
public:
Leaf(string name)
{
this->name=name;
}
void Add(Component *file){
cout<<"Cannot add to a leaf"<<endl;
}
void Remove(Component *file)
{
cout<<"Cannot remove from a leaf"<<endl;
}
list <Component *> * Get()
{
return NULL;
}
};
class Composite:public Component{
private:
list <Component *> p;
public:
Composite(string name){
this->name=name;
}
void Add(Component *file){
p.push_back(file);
}
void Remove(Component *file){
p.remove(file);
}
list <Component *> * Get()
{
this->name;
}
};
class manu:public Compsite{
//类似于dos命令下cd之类的进出命令使用
};
int main(void)
{
//略
return 0;
}
相关文章
- iOS开发:UICollectionViewCell删除的实现方法
- 引领智慧教育变革,统信软件参展第80届中国教育装备展
- 斯坦福教授曼宁:AI巨模型训练成本动辄几十万,穷博士和小公司用不起了
- 训练AI写代码还在用GitHub ?Project CodeNet或是更优解:1400万代码,50种编程语言
- 这才是中国被卡脖子最严重的软件!
- 1024程序员节,北大成立计算机学院!杨芙清任名誉院长
- 公司新招了一群程序员鼓励师,爽翻了!
- 第80届中国教育装备展示会,和统信软件一起相约天府成都
- React全新文档终于来了
- 微软推出可完全在浏览器中运行的轻量级VS Code开发环境
- 我国工业互联网发展成果初显,未来如何走深向实?
- 投资者使用AI分析CEO的语言模式和语气
- 谷歌推出开源平台 Dev Library ,展示 Google 技术相关的开源项目
- 英特尔开源基于机器学习的代码检测工具 ControlFlag
- 十张图带你彻底搞懂限流、熔断、服务降级
- 一锅端了!北京一互联网公司23人被带走…
- Gartner发布2022年重要战略技术趋势
- AI能成科学家的工具人?Nature采访五位顶尖学者:学会写代码,降低期望
- 13篇顶会!25岁成985高校博导,入职半年发ICML,网友:万点暴击
- 一场技术与思想的浪潮!1024程序员嘉年华重磅来袭