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

成都网站推广外包墨刀可以做网站原型图吗

成都网站推广外包,墨刀可以做网站原型图吗,哪个网站可以做ppt,宁波专业做网站组合模式#xff08;Composite Pattern#xff09;是一种结构型设计模式#xff0c;它允许将对象组合成树形结构来表示“部分-整体”的层次关系。组合模式能够让客户端以统一的方式对待单个对象和对象集合#xff0c;使得客户端在处理复杂树形结构的时候#xff0c;可以以…组合模式Composite Pattern是一种结构型设计模式它允许将对象组合成树形结构来表示“部分-整体”的层次关系。组合模式能够让客户端以统一的方式对待单个对象和对象集合使得客户端在处理复杂树形结构的时候可以以相同的方式对待单个对象和多个对象组合。 主要组成部分 抽象组件Component 定义了 leaf 和 composite 的对象共同实现的接口。在这里你可以定义接口的方法。 叶子Leaf 实现了抽象组件代表组合中的叶子节点。叶子节点没有子节点。 组合Composite 也实现了抽象组件代表可以有子节点的树节点。组合节点可以包含叶子或其他组合节点。 客户端Client 使用组合结构的代码通常通过接口与树结构交互。 优点 一致性客户端可以以一致的方式对待所有组成部分无论是单个对象还是组合对象。易于添加新组件可以轻松地增加新的叶子或组合无需修改现有代码。简化客户端代码客户端代码可以简单地使用组合结构不需要关注部分和整体的区别。 使用场景 需要表示对象的树形结构。客户端希望以相同的方式处理单个对象和组合对象。需要在运行时增加或删除对象。 JAVA: 创建一个文件系统的结构 // 文件系统-抽象组件 public abstract class FileSystemComponent {protected String name; //名称//构造public FileSystemComponent(String name){this.name name;}//抽象文件详情方法public abstract void showDetails(); } // 叶子类-文件 public class File extends FileSystemComponent{public File(String name) {super(name);}Overridepublic void showDetails() {System.out.println(File: name);} } // 组合类 public class Folder extends FileSystemComponent{private ListFileSystemComponent components new ArrayList();public Folder(String name) {super(name);}// 添加文件/文件夹public void addComponent(FileSystemComponent component) {components.add(component);}// 删除文件public void removeComponent(FileSystemComponent component) {components.remove(component);}Overridepublic void showDetails() {System.out.println(Folder: name);for (FileSystemComponent component : components) {component.showDetails();}} } Test(description 组合模式)public void compositeTest(){// 创建文件和文件夹File file1 new File(File1.txt);File file2 new File(File2.txt);Folder folder1 new Folder(Folder1);folder1.addComponent(file1);folder1.addComponent(file2);File file3 new File(File3.txt);Folder folder2 new Folder(Folder2);folder2.addComponent(file3);// 创建根文件夹Folder rootFolder new Folder(RootFolder);rootFolder.addComponent(folder1);rootFolder.addComponent(folder2);// 显示文件夹结构rootFolder.showDetails();} GO: 公司的人员组织就是一个典型的树状的结构现在假设我们现在有部分和员工两种角色一个部门下面可以存在子部门和员工员工下面不能再包含其他节点。 我们现在要实现一个统计一个部门下员工数量的功能 package composite// IOrganization 组织接口都实现统计人数的功能 type IOrganization interface {Count() int }// Employee 员工 type Employee struct {Name string }// Count 统计人数 func (e Employee) Count() int {return 1 }// Department 部门 type Department struct {Name stringSubOrganizations []IOrganization }// Count 人数统计 func (d Department) Count() int {c : 0for _, org : range d.SubOrganizations {c org.Count()}return c }// AddSub 添加子节点 func (d *Department) AddSub(o IOrganization) {d.SubOrganizations append(d.SubOrganizations, o) }// NewOrganization 构建组织架构 demo func NewOrganization() IOrganization {root : Department{Name: root}for i : 0; i 10; i {root.AddSub(Employee{})root.AddSub(Department{Name: sub, SubOrganizations: []IOrganization{Employee{}}})}return root }package compositeimport (github.com/stretchr/testify/asserttesting )func TestComposite(t *testing.T) {got : NewOrganization().Count()assert.Equal(t, 20, got) }
http://www.dnsts.com.cn/news/245328.html

相关文章:

  • 网站链接提交dedecms 网站地图生成
  • 仪征做网站公司哪家好安徽建设网站公司
  • 河北建设银行招聘网站网站开发价位评估
  • 网站开发过程记录册牡丹江百姓信息网
  • 广州机械网站建设外包内丘网站建设
  • 博客网站做外贸可以吗怎么用ip做网站
  • 深圳市龙岗区住房和建设局网站ps图做ppt模板下载网站
  • 门户网站设计特点杭州富阳区网站建设公司
  • 网站做推广需要什么抚州企业网站做优化
  • 揭阳智能模板建站电子商务师证官网
  • 阿坝州建设局网站刘志彬wordpress 修改目录权限设置
  • 简单详细搭建网站教程视频教程wordpress 去掉主题版权
  • 网站如何做查询表单网站备案 材料
  • 微网站方案福建省住房和城乡建设部网站
  • 定西市网站建设企业成都百度seo推广
  • 重庆网站首页制作wordpress更新后图片不显示图片
  • 网站网页制作公司建设网站服务器怎么弄
  • 邯郸做网站找哪家好公司网站流程
  • 只知道网站后台怎么做301如何开发软件app
  • 如何做网站本地服务器吗工业设计公司怎么接活
  • 开发app和网站的公司做爰全过程免费网站的视频
  • 佛山建站专简述网站设计要遵循哪些原则
  • 开发一个棋牌app需要多少钱网站优化软件下载
  • 制作网站监控推荐建站网站和维护需要会什么区别
  • 百度网站推广关键词怎么查wordpress引用
  • 河南省住房和城乡建设厅人教处网站zzcms网站开发
  • 在线做海报的网站上海百度嘉定公司网页设计
  • 免费网页制作代码上海关键词优化按天计费
  • 视频做网站邢台网站建设最新报价
  • 自助建子站国内出色的网站建设公司