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

重庆福彩建站滨江区高端网站建设

重庆福彩建站,滨江区高端网站建设,专注于网络推广及网站建设,营销型网站策划公司用途组合模式 (Component)将对象组合成树形结构以表示“部分-整体”的层次结构。组合模式使得用户对单个对象和组合对象的使用具有唯一性。组合模式是一种结构型模式。结构图-组合模式结构图Component: 组合中的对象声明接口#xff0c;在适当的情况下#xff0c;实现所有类共…用途组合模式 (Component)将对象组合成树形结构以表示“部分-整体”的层次结构。组合模式使得用户对单个对象和组合对象的使用具有唯一性。组合模式是一种结构型模式。结构图-组合模式结构图Component: 组合中的对象声明接口在适当的情况下实现所有类共有接口的默认行为。声明一个接口用于访问和管理 Component 的子部件。abstract class Component {protected String name;public Component(String name) {this.name  name;}public abstract void Add(Component c);public abstract void Remove(Component c);public abstract void Display(int depth);}Leaf: 表示叶节点对象。叶子节点没有子节点。class Leaf extends Component {public Leaf(String name) {super(name);}Overridepublic void Add(Component c) {System.out.println(Can not add to a leaf);}Overridepublic void Remove(Component c) {System.out.println(Can not remove from a leaf);}Overridepublic void Display(int depth) {String temp  ;for (int i  0; i temp  -;System.out.println(temp  name);}}Composite: 定义枝节点行为用来存储子部件在 Component 接口中实现与子部件相关的操作。例如 Add 和 Remove。class Composite extends Component {private List children  new ArrayList();public Composite(String name) {super(name);}Overridepublic void Add(Component c) {children.add(c);}Overridepublic void Remove(Component c) {children.remove(c);}Overridepublic void Display(int depth) {String temp  ;for (int i  0; i temp  -;System.out.println(temp  name);for (Component c : children) {c.Display(depth  2);}}}Client: 通过 Component 接口操作结构中的对象。public class CompositePattern {public static void main(String[] args) {Composite root  new Composite(root);root.Add(new Leaf(Leaf A));root.Add(new Leaf(Leaf B));Composite compX  new Composite(Composite X);compX.Add(new Leaf(Leaf XA));compX.Add(new Leaf(Leaf XB));root.Add(compX);Composite compXY  new Composite(Composite XY);compXY.Add(new Leaf(Leaf XYA));compXY.Add(new Leaf(Leaf XYB));compX.Add(compXY);root.Display(1);}}应用场景1、想要表示对象的部分-整体层次结构。2、想要客户端忽略组合对象与单个对象的差异客户端将统一地使用组合结构中的所有对象。关于分级数据结构的一个普遍性的例子是你每次使用电脑时所遇到的:文件系统。文件系统由目录和文件组成。每个目录都可以装内容。目录的内容可以是文件也 可以是目录。按照这种方式计算机的文件系统就是以递归结构来组织的。如果你想要描述这样的数据结构那么你可以使用组合模式。要点组合模式定义由 Leaf 对象和 Composite 对象组成的类结构它使得客户端变得简单它使得添加或删除子部件变得很容易。推荐参考资料《大话设计模式》《HeadFirst设计模式》
http://www.zqtcl.cn/news/437242/

相关文章:

  • 衡阳企业网站排名优化深圳网站建设 联雅网络
  • 厦门网站建设案例做网站需要买多大空间
  • 查看网站被恶意镜像wordpress 添加文件权限设置
  • 基于php的网站开发流程图如何建设一个公众号电影网站
  • 2018年怎么做网站排名如何提升网站的收录量
  • 租电信服务器开网站为何要屏蔽网站快照
  • 广州建设网站技术企业咨询属于什么行业
  • 哪些网站容易做网站开发价格
  • 展览网站源码棋牌游戏软件开发
  • 网站开发业务ppt做网站如何放入图像
  • 专业做网站和小程序车载网络设计是干什么的
  • 运城网站建设兼职建设通网站武义巨合汪志刚
  • 广州网站建设公司排行个人介绍网页设计模板图片
  • 东莞营销网站建设多少钱wordpress开场动画
  • 网站建设问题及解决办法网站优化过度的表现
  • html5手机网站教程合肥企业网站营销电话
  • 公司网站引导页建设银行网站怎么登录密码忘了怎么办
  • iis7 网站打不开做兼职哪个网站好
  • 惠州网站制作网站iot物联网平台开发
  • 龙岩门户网站最新仿58同城网站源码
  • 简单的企业小网站南宁最新消息今天
  • 美橙表业手表网站公司推广渠道
  • 大连网站排名优化价格wordpress锚文字
  • 漯河网做网站南京市建设工程档案馆网站
  • 重庆可以建建网站的平台天眼查 企业查询官网
  • gta5单机买房子网站在建设免费建小程序网站
  • 怎么制作网站设计图片劳动保障局瓯海劳务市场和做网站
  • 视屏网站制作青岛平台网站建设
  • asp网站做搜索义乌网站建设工作室
  • .net网站开发环境wordpress添加特效