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

网站建设仪器配置表php网站做代理服务器

网站建设仪器配置表,php网站做代理服务器,wordpress 页面连接,拖拽网站开发组合模式 描述基本使用所有节点方法一致使用 叶子无实现子节点使用 添加向上查询使用(没变化) 描述 组合模式用于描述部分与整体的关系,将个体对象与组合对象的行为统一,便于维护整个数据集。 基本使用 所有节点方法一致 定义…

组合模式

  • 描述
    • 基本使用
      • 所有节点方法一致
        • 使用
      • 叶子无实现子节点
        • 使用
    • 添加向上查询
        • 使用(没变化)

描述

组合模式用于描述部分与整体的关系,将个体对象与组合对象的行为统一,便于维护整个数据集。

基本使用

所有节点方法一致

  • 定义通用操作抽象组件
public abstract class AbstractComponent {private final String name;protected AbstractComponent(String name) {this.name = name;}public void description() {System.out.println("name: " + this.name);}public abstract void addItem(AbstractComponent child);public abstract void deleteItem(AbstractComponent child);public abstract List<AbstractComponent> getChildren();
}
  • 定义树枝节点
public class ComplexComponent extends AbstractComponent {private final List<AbstractComponent> children = new ArrayList<>();protected ComplexComponent(String name) {super(name);}public void addItem(AbstractComponent child) {children.add(child);}public void deleteItem(AbstractComponent child) {children.remove(child);}public List<AbstractComponent> getChildren() {return children;}
}
  • 定义叶子节点
public class LeafComponent extends AbstractComponent {protected LeafComponent(String name) {super(name);}@Overridepublic void addItem(AbstractComponent child) {}@Overridepublic void deleteItem(AbstractComponent child) {}@Overridepublic List<AbstractComponent> getChildren() {return null;}
}
使用

由于所有节点操作一致,在使用中无需强转

public class Sample {public static void main(String[] args) {AbstractComponent root = new ComplexComponent("L1");AbstractComponent l2 = new ComplexComponent("L2");root.addItem(l2);AbstractComponent l2_1 = new ComplexComponent("L2_1");AbstractComponent l2_2 = new ComplexComponent("L2_2");l2.addItem(l2_1);l2.addItem(l2_2);AbstractComponent l2_1_1 = new ComplexComponent("L2_1_1");l2_1.addItem(l2_1_1);AbstractComponent l2_1_2 = new ComplexComponent("L2_1_2");l2_1.addItem(l2_1_2);printComponent(root);}private static void printComponent(AbstractComponent root) {root.description();root.getChildren().forEach(component -> {if (component instanceof ComplexComponent) {printComponent(component);} else {component.description();}});}
}

叶子无实现子节点

  • 定义通用操作的抽象组件
public abstract class AbstractComponent {private final String name;protected AbstractComponent(String name) {this.name = name;}public void description() {System.out.println("name: " + this.name);}
}
  • 定义树枝节点
public class ComplexComponent extends AbstractComponent {private final List<AbstractComponent> children = new ArrayList<>();protected ComplexComponent(String name) {super(name);}public void addItem(AbstractComponent child) {children.add(child);}public void deleteItem(AbstractComponent child) {children.remove(child);}public List<AbstractComponent> getChildren() {return children;}
}
  • 定义叶子节点
public class LeafComponent extends AbstractComponent {protected LeafComponent(String name) {super(name);}
}
使用
public class Sample {public static void main(String[] args) {ComplexComponent root = new ComplexComponent("L1");ComplexComponent l2 = new ComplexComponent("L2");root.addItem(l2);ComplexComponent l2_1 = new ComplexComponent("L2_1");ComplexComponent l2_2 = new ComplexComponent("L2_2");l2.addItem(l2_1);l2.addItem(l2_2);ComplexComponent l2_1_1 = new ComplexComponent("L2_1_1");l2_1.addItem(l2_1_1);ComplexComponent l2_1_2 = new ComplexComponent("L2_1_2");l2_1.addItem(l2_1_2);printComponent(root);}private static void printComponent(ComplexComponent root) {root.description();root.getChildren().forEach(component -> {if (component instanceof ComplexComponent) {printComponent((ComplexComponent) component);} else {component.description();}});}
}

添加向上查询

在有的场景中,需要支持向上查询。
可以在通用抽象中定义一个上级节点,然后在父节点添加子节点同时为子节点关联父节点

  • 定义通用抽象组件
public abstract class AbstractComponent {private final String name;/*** 新增了一个父级成员*/private AbstractComponent parent;protected AbstractComponent(String name) {this.name = name;}public void description() {System.out.println("name: " + this.name + "  parent: " + (Objects.isNull(getParent()) ? "null" : getParent().getName()));}public abstract void addItem(AbstractComponent child);public abstract void deleteItem(AbstractComponent child);public abstract List<AbstractComponent> getChildren();public void setParent(AbstractComponent parent) {this.parent = parent;}public AbstractComponent getParent() {return parent;}public String getName() {return name;}
}
  • 定义树枝节点
public class ComplexComponent extends AbstractComponent {private final List<AbstractComponent> children = new ArrayList<>();protected ComplexComponent(String name) {super(name);}/*** 在添加子节点时 同时设置子节点的父级节点* @param child*/public void addItem(AbstractComponent child) {children.add(child);child.setParent(this);}/*** 在移除子节点时 同时清空子节点的父级节点* @param child*/public void deleteItem(AbstractComponent child) {children.remove(child);child.setParent(null);}public List<AbstractComponent> getChildren() {return children;}
}
  • 定义叶子节点(没变化)
public class LeafComponent extends AbstractComponent {protected LeafComponent(String name) {super(name);}@Overridepublic void addItem(AbstractComponent child) {}@Overridepublic void deleteItem(AbstractComponent child) {}@Overridepublic List<AbstractComponent> getChildren() {return null;}
}
使用(没变化)
public class Sample {public static void main(String[] args) {AbstractComponent root = new ComplexComponent("L1");AbstractComponent l2 = new ComplexComponent("L2");root.addItem(l2);AbstractComponent l2_1 = new ComplexComponent("L2_1");AbstractComponent l2_2 = new ComplexComponent("L2_2");l2.addItem(l2_1);l2.addItem(l2_2);AbstractComponent l2_1_1 = new ComplexComponent("L2_1_1");l2_1.addItem(l2_1_1);AbstractComponent l2_1_2 = new ComplexComponent("L2_1_2");l2_1.addItem(l2_1_2);printComponent(root);}private static void printComponent(AbstractComponent root) {root.description();root.getChildren().forEach(component -> {if (component instanceof ComplexComponent) {printComponent(component);} else {component.description();}});}
}
http://www.dtcms.com/a/505964.html

相关文章:

  • 网站建设需招聘什么专业人阿里云esc 可以做几个网站
  • 闸北区网站设计与制作百度刷排名百度快速排名
  • 免费建立自己的网站代码网络品牌推广怎么做
  • 广州洲聚网站开发成都专业logo设计公司
  • 越秀微网站建设企业展厅设计效果图
  • 北京 网站建设托管公司域名注册备案
  • o2o网站策划网站做cdn
  • 网站策划书1000字wordpress删除文章数据库
  • 深圳建设高端网站设计logo图片
  • ota平台网站建设建筑网页设计详情
  • 企业网站公司单位有哪些广州会议室租用
  • 网站打开速度优化1688seo优化是什么
  • 欧美风企业网站 英文模板wordpress分词
  • 宁波网站建设报价贵州成品网站
  • 9元建站节wordpress qtan
  • 网站建设岗位需要解决的问题全网营销推广系统
  • 软件下载免费大全网站网络营销方案设计心得
  • 重庆公司企业网站建设重庆市公共资源交易中心主任
  • 苏州姑苏区网站建设visual studio 2010 网站开发教程
  • 怎么做网站编辑电脑免费的wordpress
  • 成都网站开发的公司管理咨询的主体包括哪些
  • 一个网站一年的费用多少企业网站美化
  • 网站做关键词百度联盟一天多少收入
  • 有什么做视频的免费素材网站小语种网站案例
  • 医院网站php源码宁波模板建站源码
  • 满城区城乡建设局网站房地产开发公司税率一览表
  • 大型网站建设机构哪家好wordpress不用模版
  • 三合一网站建设多少钱珠海网站开发价格
  • 做电影下载网站需要什么小程序可做网站吗
  • 石家庄做网站最好的公司有哪些nas 做网站服务器