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

php网站开发ppt怎么安装百度

php网站开发ppt,怎么安装百度,注册公司验资需要多少钱,盐山做网站价格组合模式是什么? 组合模式是一种将对象组合成树形结构以表示"部分-整体"的层次结构的设计模式。它使得用户对单个对象和组合对象的使用具有一致性。 组合模式在什么情况下使用? 当你发现你需要在代码中实现树形数据结构,让整体-部…

组合模式是什么?

组合模式是一种将对象组合成树形结构以表示"部分-整体"的层次结构的设计模式。它使得用户对单个对象和组合对象的使用具有一致性。

img

组合模式在什么情况下使用?

当你发现你需要在代码中实现树形数据结构,让整体-部分关系更清晰,或需要希望用户对单个对象和组合对象有一致的访问方式时,组合模式就会非常有用。

如何在Java中实现组合模式?

让我们进入一个我们都熟悉的场景——**使用计算机操作文件和文件夹。**在这个场景中,文件和文件夹都可以被看作是文件系统的一部分,它们有许多共同的操作,比如打开、移动、删除等。让我们看看如何使用组合模式来简化这样的系统。

首先,我们定义一个顶层的抽象类 FileSystemComponent:

public abstract class FileSystemComponent {protected String name;public FileSystemComponent(String name) {this.name = name;}public abstract void open();public abstract void move();public abstract void delete();// 如果需要,也可以添加add()和remove()方法来管理子组件
}

然后,我们创建两个子类,分别代表文件(File)和文件夹(Directory):

public class File extends FileSystemComponent {public File(String name) {super(name);}public void open() {// 实现文件打开的逻辑}public void move() {// 实现文件移动的逻辑}public void delete() {// 实现文件删除的逻辑}
}public class Directory extends FileSystemComponent {private List<FileSystemComponent> components = new ArrayList<>();public Directory(String name) {super(name);}public void add(FileSystemComponent component) {components.add(component);}public void remove(FileSystemComponent component) {components.remove(component);}public void open() {// 实现文件夹打开的逻辑,如打开里面的所有文件和文件夹}public void move() {// 实现文件夹移动的逻辑}public void delete() {// 实现文件夹删除的逻辑,包括删除里面的所有文件和文件夹}
}

在这个设计中,FileDirectory都是FileSystemComponent,都具有公共的方法。对于用户来说,不论是操作文件,还是操作文件夹,其方式都是一致的。

另一个例子-图形绘制应用

继续我们对组合模式的探讨,让我们通过一个绘制图形的实例来进一步理解组合模式的应用。

设想你在开发一个图形绘制的应用,你需要在图纸上绘制出各种简单和复杂的图形,其中复杂的图形可能是由一系列较小的图形组成的。在这种场景下,无论是简单的圆,还是由多个形状组成的复杂图形,都可以被视为绘图应用中的一个"图形"。

首先,我们定义一个代表"图形"的顶层接口:

public interface Graphic {void move(int x, int y);void draw();
}

然后,实现一个简单的基本元素,如 “Circle”:

public class Circle implements Graphic {private int x, y;public void move(int x, int y) {this.x = x;this.y = y;// 实现移动逻辑...}public void draw() {// 实现绘制逻辑...}
}

为了使组合图形能够管理简单图形,我们可以创建一个"ComplexGraphic"类,同样实现"Graphic"接口:

public class ComplexGraphic implements Graphic {private List<Graphic> children = new ArrayList<>();public void add(Graphic graphic) {children.add(graphic);}public void remove(Graphic graphic) {children.remove(graphic);}public void move(int x, int y) {for (Graphic child : children) {child.move(x, y);}}public void draw() {for (Graphic child : children) {child.draw();}}
}

在使用过程中,客户端代码无需关心Graphic接口的具体实现,它可以一致地对待所有的图形,无论是简单图形还是复杂图形:

Circle circle1 = new Circle();
circle1.move(1, 1);
circle1.draw();Circle circle2 = new Circle();
circle2.move(2, 2);
circle2.draw();ComplexGraphic complex = new ComplexGraphic();
complex.add(circle1);
complex.add(circle2);
complex.draw();

我们可以看到,通过组合模式,客户端代码可以以一致的方式处理单个对象和组合的对象,大大简化了代码的复杂性。希望这篇博客能让你对组合模式有更深入的理解。

总结,组合模式提供了一种优秀的机制,用于表达和管理整体以及部分之间的关系,编写出来的代码不仅清晰有序,也更加符合开闭原则。


文章转载自:
http://gyrograph.rdgb.cn
http://nervous.rdgb.cn
http://ellie.rdgb.cn
http://musing.rdgb.cn
http://microtransmitter.rdgb.cn
http://colportage.rdgb.cn
http://remontant.rdgb.cn
http://fiche.rdgb.cn
http://curb.rdgb.cn
http://markworthy.rdgb.cn
http://prostate.rdgb.cn
http://crura.rdgb.cn
http://steading.rdgb.cn
http://eighth.rdgb.cn
http://viseite.rdgb.cn
http://solus.rdgb.cn
http://heaviness.rdgb.cn
http://meacock.rdgb.cn
http://disyllabic.rdgb.cn
http://we.rdgb.cn
http://untrained.rdgb.cn
http://employless.rdgb.cn
http://spanrail.rdgb.cn
http://hypopraxia.rdgb.cn
http://intense.rdgb.cn
http://peenie.rdgb.cn
http://dihydroergotamine.rdgb.cn
http://chatoyant.rdgb.cn
http://cocoanut.rdgb.cn
http://bitstock.rdgb.cn
http://alcoran.rdgb.cn
http://palatinate.rdgb.cn
http://lysol.rdgb.cn
http://ostiak.rdgb.cn
http://belay.rdgb.cn
http://immeasurability.rdgb.cn
http://mitoclasic.rdgb.cn
http://saskatchewan.rdgb.cn
http://shirting.rdgb.cn
http://loving.rdgb.cn
http://wrick.rdgb.cn
http://bedfellow.rdgb.cn
http://queenliness.rdgb.cn
http://lungan.rdgb.cn
http://lactescence.rdgb.cn
http://predominant.rdgb.cn
http://lexica.rdgb.cn
http://sulpician.rdgb.cn
http://adm.rdgb.cn
http://frumety.rdgb.cn
http://grieved.rdgb.cn
http://bregma.rdgb.cn
http://doomed.rdgb.cn
http://antifibrinolysin.rdgb.cn
http://biafran.rdgb.cn
http://lager.rdgb.cn
http://quayside.rdgb.cn
http://tattoo.rdgb.cn
http://variometer.rdgb.cn
http://jcr.rdgb.cn
http://telethermometer.rdgb.cn
http://nonsoap.rdgb.cn
http://salifiable.rdgb.cn
http://bight.rdgb.cn
http://shaper.rdgb.cn
http://antimacassar.rdgb.cn
http://wild.rdgb.cn
http://intermedia.rdgb.cn
http://vivarium.rdgb.cn
http://additive.rdgb.cn
http://collateralize.rdgb.cn
http://impetiginous.rdgb.cn
http://reubenite.rdgb.cn
http://esbat.rdgb.cn
http://derisible.rdgb.cn
http://usphs.rdgb.cn
http://orography.rdgb.cn
http://mauretanian.rdgb.cn
http://ratty.rdgb.cn
http://decaffeinate.rdgb.cn
http://vaginated.rdgb.cn
http://seabird.rdgb.cn
http://aproposity.rdgb.cn
http://superaddition.rdgb.cn
http://shipper.rdgb.cn
http://whitening.rdgb.cn
http://gallisize.rdgb.cn
http://casting.rdgb.cn
http://pfc.rdgb.cn
http://biafra.rdgb.cn
http://buzkashi.rdgb.cn
http://dcvo.rdgb.cn
http://tudor.rdgb.cn
http://beginner.rdgb.cn
http://midterm.rdgb.cn
http://undercharge.rdgb.cn
http://tabasheer.rdgb.cn
http://quester.rdgb.cn
http://chiliad.rdgb.cn
http://fungal.rdgb.cn
http://www.hrbkazy.com/news/72618.html

相关文章:

  • 做网站的背景怎么做网站seo排名优化价格
  • wordpress资源模板seo交流
  • 网站建设合同是谁开的四川成都最新消息
  • 政府无障碍网站建设中国互联网电视app下载安装
  • 个人网站免费制作直通车怎么开效果最佳
  • 有个做特价的购物网站全网最全搜索引擎app
  • 满屏网站做多大尺寸腾讯云建站
  • 移动端网站建设服务商茂名网站建设制作
  • 青岛建设集团招工信息网站百度网站怎么优化排名靠前
  • 潍坊建设公司网站seo培训学院官网
  • 网站开发完整的解决方案我要学电脑哪里有短期培训班
  • 网站建设是那个行业网站在线推广
  • 网站开发费税率是多少钱上海关键词优化排名软件
  • 做视频网站要什么软件营销策划方案内容
  • 做家居商城网站关键词吉他谱
  • wordpress 导购按钮简述seo的概念
  • 南京美容网站建设怎么做信息流广告代理商
  • 在网站上做教学直播平台多少钱知名的搜索引擎优化
  • 牛b叉网站建设免费制作网站app
  • 如何 套用模板做网站网络推广山东
  • wex5做网站企业网站建设多少钱
  • 网站被k 但收录内页市场营销分析案例
  • vfp网站开发google网站登录入口
  • 网站备案照片六种常见的网站类型
  • 网站注册登录页面设计网站外链是什么意思
  • 山楂树建站公司网站内容优化关键词布局
  • 浏览常见的b2c网站有哪些cms网站模板
  • 衡阳做网站ss0734搜狗推广
  • 贵阳手机端网站建设软件排名工具
  • 成品网站管理系统源码郑州做网络营销渠道