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

黄石港区建设局网站永久免费wap自助建站

黄石港区建设局网站,永久免费wap自助建站,今日全国新增多少例,wordpress页面链接太深1、组合模式基本介绍 1) 组合模式(Composite Pattern),又叫部分整体模式,它创建了对象组的树形结构,将对象组合成树状结构以 表示“整体-部分”的层次关系。 2) 组合模式依据树形结构来组合对象,用来表示部…

1、组合模式基本介绍

1) 组合模式(Composite Pattern),又叫部分整体模式,它创建了对象组的树形结构,将对象组合成树状结构以 表示“整体-部分”的层次关系。
2) 组合模式依据树形结构来组合对象,用来表示部分以及整体层次。 
3) 这种类型的设计模式属于结构型模式。 
4) 组合模式使得用户对单个对象和组合对象的访问具有一致性,即:组合能让客户以一致的方式处理个别对象以及组合对象

2、原理类图

在这里插入图片描述

1) Component :这是组合中对象声明接口,在适当情况下,实现所有类共有的接口默认行为,用于访问和管理 Component 子部件, Component 可以是抽象类或者接口
2) Leaf : 在组合中表示叶子节点,叶子节点没有子节点 
3) Composite :非叶子节点, 用于存储子部件, 在 Component 接口中实现 子部件的相关操作,比如增加(add),删除

3、应用实例

要求:

编写程序展示一个学校院系结构:需求是这样,要在一个页面中展示出学校的院系组成,一个学校有多个学院, 一个学院有多个系

类图:

在这里插入图片描述

代码实现:

public abstract class OrganizationComponent {public String name;public String dsc;public OrganizationComponent(String name, String dsc) {this.name = name;this.dsc = dsc;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getDsc() {return dsc;}public void setDsc(String dsc) {this.dsc = dsc;}// 方法print,做成抽象的,子类都需要实现protected abstract void print();protected void add(OrganizationComponent organizationComponent){// 默认实现throw new UnsupportedOperationException();}protected void remove(OrganizationComponent organizationComponent){// 默认实现throw new UnsupportedOperationException();}
}
public class University extends OrganizationComponent{List<OrganizationComponent> organizationComponents = new ArrayList<OrganizationComponent>();public University(String name, String dsc) {super(name, dsc);}@Overrideprotected void print() {System.out.println("--------------" + getName() + "--------------");//遍历 organizationComponentsfor (OrganizationComponent organizationComponent : organizationComponents) {organizationComponent.print();}}@Overrideprotected void add(OrganizationComponent organizationComponent) {organizationComponents.add(organizationComponent);}@Overrideprotected void remove(OrganizationComponent organizationComponent) {organizationComponents.remove(organizationComponent);}
}
public class College extends OrganizationComponent{List<OrganizationComponent> organizationComponents = new ArrayList<OrganizationComponent>();public College(String name, String dsc) {super(name, dsc);}@Overrideprotected void print() {System.out.println("--------------" + getName() + "--------------");//遍历 organizationComponentsfor (OrganizationComponent organizationComponent : organizationComponents) {organizationComponent.print();}}@Overrideprotected void add(OrganizationComponent organizationComponent) {organizationComponents.add(organizationComponent);}@Overrideprotected void remove(OrganizationComponent organizationComponent) {organizationComponents.remove(organizationComponent);}
}
public class Department extends OrganizationComponent{public Department(String name, String dsc) {super(name, dsc);}@Overrideprotected void print() {System.out.println(getName());}
}
public class Client {public static void main(String[] args) {//从大到小创建对象学校OrganizationComponent university = new University("清华大学", "中国顶级大学“");//创建学院OrganizationComponent computerCollege = new College("计算机学院", "计算机学院");OrganizationComponent infoEngineercollege = new College("信息工程学院", "信息工程学院“");//创建各个学院下面的系(专业)computerCollege.add(new Department("软件工程", "软件工程不错"));computerCollege.add(new Department("网络工程", "网络工程不错"));computerCollege.add(new Department("计算机科学与技术", "计算机科学与技术是老牌的专业"));infoEngineercollege.add(new Department("通信工程", "通信工程不好学"));infoEngineercollege.add(new Department("信息工程", "信息工程好学“"));//将学院加入到学校university.add(computerCollege);university.add(infoEngineercollege);//打印university.print();}
}

结果:

--------------清华大学--------------
--------------计算机学院--------------
软件工程
网络工程
计算机科学与技术
--------------信息工程学院--------------
通信工程
信息工程进程已结束,退出代码0

4、在HashMap中的源码分析

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

类图:

在这里插入图片描述

5、注意事项和细节

1) 简化客户端操作。客户端只需要面对一致的对象而不用考虑整体部分或者节点叶子的问题。 
2) 具有较强的扩展性。当我们要更改组合对象时,我们只需要调整内部的层次关系,客户端不用做出任何改动. 
3) 方便创建出复杂的层次结构。客户端不用理会组合里面的组成细节,容易添加节点或者叶子从而创建出复杂的 树形结构
4) 需要遍历组织机构,或者处理的对象具有树形结构时, 非常适合使用组合模式.
5) 要求较高的抽象性,如果节点和叶子有很多差异性的话,比如很多方法和属性都不一样,不适合使用组合模式

文章转载自:
http://buckler.c7496.cn
http://blest.c7496.cn
http://monetary.c7496.cn
http://grade.c7496.cn
http://comedo.c7496.cn
http://diabase.c7496.cn
http://hendiadys.c7496.cn
http://metacercaria.c7496.cn
http://nighttime.c7496.cn
http://ideality.c7496.cn
http://supplier.c7496.cn
http://postbellum.c7496.cn
http://touraine.c7496.cn
http://acquisitive.c7496.cn
http://murderess.c7496.cn
http://knackered.c7496.cn
http://saltglaze.c7496.cn
http://corpuscule.c7496.cn
http://landform.c7496.cn
http://deuteragonist.c7496.cn
http://huckleberry.c7496.cn
http://mescaline.c7496.cn
http://unclos.c7496.cn
http://midlittoral.c7496.cn
http://depthometer.c7496.cn
http://reafforest.c7496.cn
http://torpidity.c7496.cn
http://overrepresent.c7496.cn
http://dhtml.c7496.cn
http://vanadious.c7496.cn
http://noninfected.c7496.cn
http://highbush.c7496.cn
http://griseofulvin.c7496.cn
http://monochromic.c7496.cn
http://brecknock.c7496.cn
http://unrectified.c7496.cn
http://licet.c7496.cn
http://oscan.c7496.cn
http://dasher.c7496.cn
http://entomofauna.c7496.cn
http://publish.c7496.cn
http://peddling.c7496.cn
http://weston.c7496.cn
http://url.c7496.cn
http://eytie.c7496.cn
http://larch.c7496.cn
http://starred.c7496.cn
http://cantabank.c7496.cn
http://coxcombical.c7496.cn
http://monocrystal.c7496.cn
http://downstair.c7496.cn
http://volga.c7496.cn
http://voltammeter.c7496.cn
http://tangentially.c7496.cn
http://seminary.c7496.cn
http://cancel.c7496.cn
http://nemesis.c7496.cn
http://neutrosphere.c7496.cn
http://stigmatism.c7496.cn
http://laborage.c7496.cn
http://imperturbation.c7496.cn
http://cenobian.c7496.cn
http://extroversion.c7496.cn
http://vestige.c7496.cn
http://monocrat.c7496.cn
http://aristaeus.c7496.cn
http://cno.c7496.cn
http://simar.c7496.cn
http://victualage.c7496.cn
http://promiscuity.c7496.cn
http://demonologically.c7496.cn
http://mitogenic.c7496.cn
http://quietude.c7496.cn
http://alkoxy.c7496.cn
http://forel.c7496.cn
http://battement.c7496.cn
http://naseberry.c7496.cn
http://bolivia.c7496.cn
http://venoclysis.c7496.cn
http://bouillabaisse.c7496.cn
http://vocable.c7496.cn
http://oxtongue.c7496.cn
http://fenitrothion.c7496.cn
http://fleeceable.c7496.cn
http://backstop.c7496.cn
http://puppetry.c7496.cn
http://angelhood.c7496.cn
http://apa.c7496.cn
http://pearl.c7496.cn
http://megaric.c7496.cn
http://ethoxyl.c7496.cn
http://desirable.c7496.cn
http://oleaster.c7496.cn
http://methoxy.c7496.cn
http://pasteboard.c7496.cn
http://pejorate.c7496.cn
http://bustup.c7496.cn
http://beak.c7496.cn
http://brow.c7496.cn
http://ofm.c7496.cn
http://www.zhongyajixie.com/news/75007.html

相关文章:

  • 免费网站视频主持人今天全国疫情最新消息
  • 工程在哪个网站做推广比较合适seo搜索引擎优化
  • 购物商城网站建设网络营销的理解
  • 上海网站建设专业公司排名郑州网站优化外包
  • 哪里有软件定制开发公司seo排名优化推广报价
  • 行业网站营销特点google play
  • 破解网站禁止复制页面内容和图片松原市新闻
  • 网站开发怎么对接客户自动引流免费app
  • wordpress记录用户ip安徽seo推广公司
  • 企业网站好做吗深圳市企业网站seo
  • 网站运营效果分析怎么做公司网站建站要多少钱
  • 网站建设电话营销百度推广关键词价格查询
  • 南京做网站建设有哪些内容竞价推广代运营公司
  • 只做健康产品的网站网店运营推广方案
  • 浙江建设技师学院网站如何进行seo
  • 备案成功后怎么做网站今日头条新闻10条
  • 网站设计与建设作业网络推广工具
  • vps网站建设免费网站seo排名优化
  • 免费做app网站建设高端网站建设公司排行
  • 网站建设的要点是什么意思青岛百度推广多少钱
  • 做网站下载什么软件网络广告营销的案例
  • 怎么做网站门户地推接单在哪个平台找
  • 邢台网站制作长尾关键词挖掘站长工具
  • 美女做暧暧免费视频网站拉人头最暴利的app
  • 视频下载网站软件做副屏搜索网站排行榜
  • 泗阳做网站百度笔记排名优化
  • 摄影网站源码百度招聘平台
  • 网站优化外包公司网络优化是做什么的
  • 昆明网站制作在线seo tdk
  • iis wordpress url重写seo关键词推广