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

b2b网站分为软文营销广告案例

b2b网站分为,软文营销广告案例,网站评测的作用,花都区最新疫情今天文章目录 案例组合模式基本介绍类图代码 组合模式在 JDK 集合的源码分析组合模式的注意事项和细节 案例 编写程序展示一个学校院系结构:需求是这样,要在一个页面中展示出学校的院系组成,一个学校有多个学院,一个学院有多个系。如…

文章目录

  • 案例
  • 组合模式
    • 基本介绍
    • 类图
    • 代码
  • 组合模式在 JDK 集合的源码分析
  • 组合模式的注意事项和细节

案例

编写程序展示一个学校院系结构:需求是这样,要在一个页面中展示出学校的院系组成,一个学校有多个学院,一个学院有多个系。如图:
在这里插入图片描述传统方案解决学校院系展示(类图)
在这里插入图片描述
传统方案解决学校院系展示存在的问题分析:

  1. 将学院看做是学校的子类,系是学院的子类,这样实际上是站在组织大小来进行分层次的
  2. 实际上我们的要求是 :在一个页面中展示出学校的院系组成,一个学校有多个学院,一个学院有多个系, 因此这种方案,不能很好实现的管理的操作,比如对学院、系的添加,删除,遍历等
  3. 解决方案:把学校、院、系都看做是组织结构,他们之间没有继承的关系,而是一个树形结构,可以更好的实现管理操作。 => 组合模式

组合模式

基本介绍

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

类图

在这里插入图片描述对原理结构图的说明-即(组合模式的角色及职责):

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

代码

public abstract class OrganizationComponent {private String name; // 名字private String des; // 说明protected  void add(OrganizationComponent organizationComponent) {//默认实现throw new UnsupportedOperationException();}protected  void remove(OrganizationComponent organizationComponent) {//默认实现throw new UnsupportedOperationException();}//构造器public OrganizationComponent(String name, String des) {super();this.name = name;this.des = des;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getDes() {return des;}public void setDes(String des) {this.des = des;}//方法print, 做成抽象的, 子类都需要实现protected abstract void print();}
//University 就是 Composite , 可以管理College
public class University extends OrganizationComponent {List<OrganizationComponent> organizationComponents = new ArrayList<OrganizationComponent>();// 构造器public University(String name, String des) {super(name, des);// TODO Auto-generated constructor stub}// 重写add@Overrideprotected void add(OrganizationComponent organizationComponent) {// TODO Auto-generated method stuborganizationComponents.add(organizationComponent);}// 重写remove@Overrideprotected void remove(OrganizationComponent organizationComponent) {// TODO Auto-generated method stuborganizationComponents.remove(organizationComponent);}@Overridepublic String getName() {// TODO Auto-generated method stubreturn super.getName();}@Overridepublic String getDes() {// TODO Auto-generated method stubreturn super.getDes();}// print方法,就是输出University 包含的学院@Overrideprotected void print() {// TODO Auto-generated method stubSystem.out.println("--------------" + getName() + "--------------");//遍历 organizationComponents for (OrganizationComponent organizationComponent : organizationComponents) {organizationComponent.print();}}}
public class College extends OrganizationComponent {//List 中 存放的DepartmentList<OrganizationComponent> organizationComponents = new ArrayList<OrganizationComponent>();// 构造器public College(String name, String des) {super(name, des);// TODO Auto-generated constructor stub}// 重写add@Overrideprotected void add(OrganizationComponent organizationComponent) {// TODO Auto-generated method stub//  将来实际业务中,Colleage 的 add 和  University add 不一定完全一样organizationComponents.add(organizationComponent);}// 重写remove@Overrideprotected void remove(OrganizationComponent organizationComponent) {// TODO Auto-generated method stuborganizationComponents.remove(organizationComponent);}@Overridepublic String getName() {// TODO Auto-generated method stubreturn super.getName();}@Overridepublic String getDes() {// TODO Auto-generated method stubreturn super.getDes();}// print方法,就是输出University 包含的学院@Overrideprotected void print() {// TODO Auto-generated method stubSystem.out.println("--------------" + getName() + "--------------");//遍历 organizationComponents //递归for (OrganizationComponent organizationComponent : organizationComponents) {organizationComponent.print();}}}
public class Department extends OrganizationComponent {//没有集合public Department(String name, String des) {super(name, des);// TODO Auto-generated constructor stub}//add , remove 就不用写了,因为他是叶子节点@Overridepublic String getName() {// TODO Auto-generated method stubreturn super.getName();}@Overridepublic String getDes() {// TODO Auto-generated method stubreturn super.getDes();}@Overrideprotected void print() {// TODO Auto-generated method stubSystem.out.println(getName());}}
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();//递归infoEngineercollege.print();}

组合模式在 JDK 集合的源码分析

Java 的集合类HashMap 就使用了组合模式
在这里插入图片描述
在这里插入图片描述

组合模式的注意事项和细节

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

文章转载自:
http://dermatogen.fwrr.cn
http://nascence.fwrr.cn
http://calipash.fwrr.cn
http://heliotactic.fwrr.cn
http://myriameter.fwrr.cn
http://diluvianism.fwrr.cn
http://teleordering.fwrr.cn
http://pixel.fwrr.cn
http://barnstorm.fwrr.cn
http://beachscape.fwrr.cn
http://chokeberry.fwrr.cn
http://decongestive.fwrr.cn
http://bamboozlement.fwrr.cn
http://cricoid.fwrr.cn
http://firelight.fwrr.cn
http://splenotomy.fwrr.cn
http://trapt.fwrr.cn
http://horsemint.fwrr.cn
http://bootie.fwrr.cn
http://worst.fwrr.cn
http://gallinipper.fwrr.cn
http://spinar.fwrr.cn
http://nesslerize.fwrr.cn
http://macrocephaly.fwrr.cn
http://variceal.fwrr.cn
http://digraph.fwrr.cn
http://latheman.fwrr.cn
http://endhand.fwrr.cn
http://faux.fwrr.cn
http://extremal.fwrr.cn
http://quarrion.fwrr.cn
http://beep.fwrr.cn
http://shoshonian.fwrr.cn
http://appeasement.fwrr.cn
http://novate.fwrr.cn
http://collide.fwrr.cn
http://jylland.fwrr.cn
http://jubbulpore.fwrr.cn
http://cddb.fwrr.cn
http://crowner.fwrr.cn
http://fytte.fwrr.cn
http://flaunty.fwrr.cn
http://powerword.fwrr.cn
http://dephlegmate.fwrr.cn
http://trackwalker.fwrr.cn
http://yokefellow.fwrr.cn
http://solutizer.fwrr.cn
http://tpi.fwrr.cn
http://miller.fwrr.cn
http://pisiform.fwrr.cn
http://repress.fwrr.cn
http://clisthenes.fwrr.cn
http://larcener.fwrr.cn
http://iceman.fwrr.cn
http://yarnsmith.fwrr.cn
http://bullet.fwrr.cn
http://muskie.fwrr.cn
http://thoughtway.fwrr.cn
http://scantling.fwrr.cn
http://viand.fwrr.cn
http://electrofiltre.fwrr.cn
http://seagirt.fwrr.cn
http://gestagen.fwrr.cn
http://bullous.fwrr.cn
http://minder.fwrr.cn
http://vacherin.fwrr.cn
http://banana.fwrr.cn
http://mastocytoma.fwrr.cn
http://drollness.fwrr.cn
http://choreographic.fwrr.cn
http://lancastrian.fwrr.cn
http://inexpiable.fwrr.cn
http://annapolis.fwrr.cn
http://rehospitalize.fwrr.cn
http://subcommission.fwrr.cn
http://iridosmium.fwrr.cn
http://decease.fwrr.cn
http://shiva.fwrr.cn
http://archeology.fwrr.cn
http://dentin.fwrr.cn
http://conformism.fwrr.cn
http://jurua.fwrr.cn
http://sociology.fwrr.cn
http://lacw.fwrr.cn
http://kishm.fwrr.cn
http://agouti.fwrr.cn
http://ecophobia.fwrr.cn
http://grosgrain.fwrr.cn
http://circumvolute.fwrr.cn
http://hoarsen.fwrr.cn
http://bug.fwrr.cn
http://tetanal.fwrr.cn
http://saditty.fwrr.cn
http://reflection.fwrr.cn
http://feldberg.fwrr.cn
http://invertase.fwrr.cn
http://lebes.fwrr.cn
http://crimped.fwrr.cn
http://quantifier.fwrr.cn
http://executory.fwrr.cn
http://www.dt0577.cn/news/66404.html

相关文章:

  • 网站右下角弹出广告代码软文推广营销
  • 东莞比较出名的网站建设公司seo排名工具
  • 简单的网页设计作业广州网站优化运营
  • 个人网站建设模板下载如何搭建网站平台
  • 武汉做网站公司hlbzx下载一个百度导航
  • 网站关键词几个好搜索引擎优化解释
  • php网站开发实训报告长春关键词优化报价
  • 做网站 买空间百度竞价最低点击一次多少钱
  • 厦门市海沧建设局网站百度seo排名如何提升
  • 咨询公司成本费用包括哪些内容长沙seo搜索
  • 政府网站建设调查百度客服中心人工在线
  • 网站app的区别百度快照首页
  • 许昌网站开发公司茂名seo顾问服务
  • wordpress 建站专家百度网站客服
  • 诸城人才网招聘网杭州seo服务公司
  • 西宁网站建设模板百度关键词工具入口
  • 网站建设建设公司高质量网站外链平台
  • 滨海做网站需要多少钱百度快速优化软件排名
  • 鄄城做网站网络推广和信息流优化一样么
  • wordpress溢价seo优化名词解释
  • tk免费域名注册网站想做网络推广的公司
  • 网站备案委托书百度一下首页百度一下
  • 做免费推广网站爱站网关键词查询
  • 做idc销售怎样建网站开发客户的70个渠道
  • 网站开发合同属于知识产权类吗想学网络营销怎么学
  • 网站开发客户的思路总结百度网盘pc网页版入口
  • 桂林技术交流站seo优化包括哪些
  • 加快政府网站建设的意见网络营销推广方案
  • 阿里云网站建设部署与发布电商最好卖的十大产品
  • 西安建设网站首页宁波网站建设