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

网站代理工具h5入口

网站代理工具,h5入口,成都网站建设网络公司,网络运维工程师需要考什么证书组合设计模式(Composite Pattern)是结构型设计模式之一,它的核心思想是将对象组合成树形结构来表示“部分-整体”的层次结构,使得用户对单个对象和组合对象的使用具有一致性。 主要概念: 组件(Component&a…

组合设计模式(Composite Pattern)是结构型设计模式之一,它的核心思想是将对象组合成树形结构来表示“部分-整体”的层次结构,使得用户对单个对象和组合对象的使用具有一致性。

主要概念:

  1. 组件(Component):定义一个接口,用于访问和操作所有的对象(包括叶子节点和组合节点)。

  2. 叶子节点(Leaf):表示树的叶子节点,没有子节点,继承组件接口并实现具体行为。

  3. 组合节点(Composite):表示树中的分支节点,可以包含叶子节点或者其他组合节点,同样继承组件接口并实现具体行为,同时还会提供对子节点的管理功能(例如添加、删除)。private List<OrganizationComponent> components = new ArrayList<>();                       public void addComponent(OrganizationComponent component) {
            components.add(component);
        } 

@Override
    public void showDetails() {
        System.out.println("Department: " + name);
        for (OrganizationComponent component : components) {
            component.showDetails();
        }
    }

适用场景:

  • 当需要表示对象的“部分-整体”层次结构时。

  • 客户端希望统一对待单个对象和组合对象时。

  • 需要在系统中处理树形结构的数据时,比如图形界面中树形结构的布局。

示例:

假设我们有一个组织结构的系统,包含员工(叶子节点)和部门(组合节点),每个部门下可能包含多个员工或子部门。

// 组件接口
interface OrganizationComponent {void showDetails();
}// 叶子节点(员工)
class Employee implements OrganizationComponent {private String name;public Employee(String name) {this.name = name;}@Overridepublic void showDetails() {System.out.println("Employee: " + name);}
}// 组合节点(部门)
class Department implements OrganizationComponent {private String name;private List<OrganizationComponent> components = new ArrayList<>();public Department(String name) {this.name = name;}public void addComponent(OrganizationComponent component) {components.add(component);}@Overridepublic void showDetails() {System.out.println("Department: " + name);for (OrganizationComponent component : components) {component.showDetails();}}
}使用
public class CompositePatternDemo {public static void main(String[] args) {OrganizationComponent emp1 = new Employee("Alice");OrganizationComponent emp2 = new Employee("Bob");Department dept1 = new Department("HR");dept1.addComponent(emp1);dept1.addComponent(emp2);OrganizationComponent emp3 = new Employee("Charlie");Department dept2 = new Department("Finance");dept2.addComponent(emp3);Department headOffice = new Department("Head Office");headOffice.addComponent(dept1);headOffice.addComponent(dept2);headOffice.showDetails(); // 打印整个组织结构}
}输出
public class CompositePatternDemo {public static void main(String[] args) {OrganizationComponent emp1 = new Employee("Alice");OrganizationComponent emp2 = new Employee("Bob");Department dept1 = new Department("HR");dept1.addComponent(emp1);dept1.addComponent(emp2);OrganizationComponent emp3 = new Employee("Charlie");Department dept2 = new Department("Finance");dept2.addComponent(emp3);Department headOffice = new Department("Head Office");headOffice.addComponent(dept1);headOffice.addComponent(dept2);headOffice.showDetails(); // 打印整个组织结构}
}

http://www.dtcms.com/a/526136.html

相关文章:

  • wordpress 站内通知在墙外的优质网站
  • 北碚集团网站建设手机网站 动态 页面 好 静态页面好
  • 网站留言板怎么做phpsql网站建站企业
  • 企业展示型网站程序建筑设计公司注册
  • 自助个人免费网站打开网站是空白页面
  • 怎么做网站规划书利为汇wordpress教程
  • 浙江海滨建设集团有限公司网站wordpress模板修改内容
  • 34.CentOS-Stream-8-packstack安装OpenStack-Victoria
  • 阿里云 CentOS 磁盘扩容记录:resize2fs 版本过低导致无法扩容的解决方案
  • 网站建设资质要求如何做网站卖画
  • 互联网服务网站建设目的wordpress 清楚jq
  • 松岗做网站价格wordpress 常见问题
  • 从浪涌防护到系统可控,天硕工业级SSD重构工业存储安全体系
  • C++ 知识体系
  • 网上做任务网站装饰工程施工
  • xml网站模板媒体营销平台
  • 将 m 个相同的苹果放入 n 个相同的盘子中
  • 新手学做网站学要做哪些网站 配色
  • 酒店网站建设方案兰州最好的网站建设公司
  • 装潢公司网站设计与制作设计汽车网站
  • 做交易网站网站办公室文化建设
  • 青岛英文网站建设网站带搜索功能怎么做
  • Flink CDC实时数据同步与小时级统计方案(Flink 1.13.5 + MySQL 8.0)
  • 使页面具有动态效果的网站建设技术关键词搜索推广排行榜
  • dw asp access 网站开发优点网站手机页面如何做
  • discuz网站建设教学视频做视频网站免费观看爱
  • 电子商务网站开发技术路线网上做网站兼职
  • 百度搜索网站数字选用平台介绍
  • 制作简历seo搜索引擎优化招聘
  • 网站返回首页怎么做的好看虚拟产品网站