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

中国门户网站有哪些推广计划方案

中国门户网站有哪些,推广计划方案,北京交友最好的网站建设,网站建设 概念1、简介 1.1、概述 在软件开发时,经常需要使用聚合对象来存储一系列数据。聚合对象拥有两个职责:一是存储数据;二是遍历数据。从依赖性来看,前者是聚合对象的基本职责;而后者既是可变化的,又是可分离的。…

1、简介

1.1、概述

在软件开发时,经常需要使用聚合对象来存储一系列数据。聚合对象拥有两个职责:一是存储数据;二是遍历数据。从依赖性来看,前者是聚合对象的基本职责;而后者既是可变化的,又是可分离的。因此,可以将遍历数据的行为从聚合对象中分离出来,封装在一个被称之为“迭代器”的对象中。由迭代器来提供遍历聚合对象内部数据的行为,这将简化聚合对象的设计,更符合单一职责原则的要求。

1.2、定义

迭代器模式(Iterator Pattern):提供一种方法来访问聚合对象,而不用暴露这个对象的内部表示,其别名为游标(Cursor)。迭代器模式是一种对象行为型模式。

2、解析

2.1、UML类图

在迭代器模式结构中包含聚合和迭代器两个层次结构。考虑到系统的灵活性和可扩展性,在迭代器模式中应用了工厂方法模式,其模式结构如下图所示。
在这里插入图片描述
可以看出,在迭代器模式结构图中包含以下4个角色:

  1. Iterator(抽象迭代器):它定义了访问和遍历元素的接口,声明了用于遍历数据元素的方法。例如,用于获取第一个元素的first()方法,用于访问下一个元素的next()方法,用于判断是否还有下一个元素的hasNext()方法,用于获取当前元素的currentItem()方法等。在具体迭代器中将实现这些方法。
  2. ConcreteIterator(具体迭代器):它实现了抽象迭代器接口,完成对聚合对象的遍历,同时在具体迭代器中通过游标来记录在聚合对象中所处的当前位置。在具体实现时,游标通常是一个表示位置的非负整数。
  3. Aggregate(抽象聚合类):它用于存储和管理元素对象,声明一个createIterator()方法用于创建一个迭代器对象,充当抽象迭代器工厂角色。
  4. ConcreteAggregate(具体聚合类):它实现了在抽象聚合类中声明的createIterator()方法,该方法返回一个与该具体聚合类对应的具体迭代器ConcreteIterator实例。

2.2、代码示例

在迭代器模式中应用了工厂方法模式,抽象迭代器对应于抽象产品角色,具体迭代器对应于具体产品角色,抽象聚合类对应于抽象工厂角色,具体聚合类对应于具体工厂角色。

在抽象迭代器中声明了用于遍历聚合对象中所存储元素的方法,典型代码如下:

interface Iterator{public void first(); // 将游标指向第一个元素public void next(); // 将游标指向下一个元素public boolean hasNext(); // 判断是否存在下一个元素public Object currentItem(); // 获取游标指向的当前元素
}

在具体迭代器中将实现在抽象迭代器中声明的遍历数据方法,代码如下:

class ConcreteIterator implements Iterator{// 维持一个对具体聚合对象的引用,以便于访问存储在聚合对象中的数据private int cursor; // 定义一个游标,用于记录当前访问位置public ConcreteIterator(ConcreteAggregate object){this.object=object;}public void first(){}public void next(){}public boolean hasNext(){}public Object currentItem(){}
}

需要注意的是,抽象迭代器接口的设计非常重要。一方面需要充分满足各种遍历操作的要求,尽量为各种遍历方法都提供声明;另一方面又不能包含太多方法,接口中方法太多将给子类的实现带来麻烦。因此,可以考虑使用抽象类来设计抽象迭代器,在抽象类中为每一个方法提供一个空的默认实现。如果需要在具体迭代器中为聚合对象增加全新的遍历操作,则必须修改抽象迭代器和具体迭代器的源代码,这将违反开闭原则,因此在设计时要考虑全面,避免之后修改接口。

聚合类用于存储数据并负责创建迭代器对象。最简单的抽象聚合类代码如下:

interface Aggregate{Iterator createIterator();
}

具体聚合类作为抽象聚合类的子类,一方面负责存储数据,另一方面实现了在抽象聚合类中声明的工厂方法createIterator(),用于返回一个与该具体聚合类对应的具体迭代器对象。代码如下:

class ConcreteAggregate implements Aggregate{public Iterator createIterator(){return new ConcreteIterator(this); }}

3、迭代器模式总结

迭代器模式是一种使用频率非常高的设计模式,通过引入迭代器可以将数据的遍历功能从聚合对象中分离出来。聚合对象只负责存储数据,而遍历数据由迭代器来完成。由于很多编程语言的类库都已经实现了迭代器模式,因此在实际开发中,只需要直接使用Java、C#等语言已定义好的迭代器即可。迭代器已经成为操作聚合对象的基本工具之一。

3.1、主要优点

  1. 支持以不同的方式遍历一个聚合对象,在同一个聚合对象上可以定义多种遍历方式。在迭代器模式中只需要用一个不同的迭代器来替换原有迭代器即可改变遍历算法,也可以自己定义迭代器的子类以支持新的遍历方式。
  2. 迭代器简化了聚合类。由于引入了迭代器,在原有的聚合对象中不需要再自行提供数据遍历等方法,这样可以简化聚合类的设计。
  3. 在迭代器模式中,由于引入了抽象层,增加新的聚合类和迭代器类都很方便,无须修改原有代码,满足开闭原则的要求。

3.2、主要缺点

  1. 由于迭代器模式将存储数据和遍历数据的职责分离,增加新的聚合类需要对应增加新的迭代器类,类的个数成对增加,这在一定程度上增加了系统的复杂性。
  2. 抽象迭代器的设计难度较大,需要充分考虑到系统将来的扩展。例如JDK内置迭代器Iterator就无法实现逆向遍历,如果需要实现逆向遍历,只能通过其子类ListIterator等来实现,而ListIterator迭代器无法用于操作Set类型的聚合对象。在自定义迭代器时,创建一个考虑全面的抽象迭代器并不是件很容易的事情。

3.3、适用场景

  1. 访问一个聚合对象的内容而无须暴露它的内部表示。将聚合对象的访问与内部数据的存储分离,使得访问聚合对象时无须了解其内部实现细节。
  2. 需要为一个聚合对象提供多种遍历方式。
  3. 为遍历不同的聚合结构提供一个统一的接口,在该接口的实现类中为不同的聚合结构提供不同的遍历方式,而客户端可以一致性地操作该接口。

文章转载自:
http://dinncomultination.ydfr.cn
http://dinncodelectus.ydfr.cn
http://dinncoflatwoods.ydfr.cn
http://dinncotrepan.ydfr.cn
http://dinncosalmon.ydfr.cn
http://dinncojangler.ydfr.cn
http://dinncotrover.ydfr.cn
http://dinncoreapproach.ydfr.cn
http://dinncohessian.ydfr.cn
http://dinncopogonology.ydfr.cn
http://dinncobangbang.ydfr.cn
http://dinncomasked.ydfr.cn
http://dinncopinwork.ydfr.cn
http://dinncocounteractant.ydfr.cn
http://dinncoirradiant.ydfr.cn
http://dinncoorganization.ydfr.cn
http://dinncobegohm.ydfr.cn
http://dinnconiggra.ydfr.cn
http://dinncoaminophenol.ydfr.cn
http://dinncolawlike.ydfr.cn
http://dinncohowdah.ydfr.cn
http://dinncoingesta.ydfr.cn
http://dinncosnaphaunce.ydfr.cn
http://dinncosubstratosphere.ydfr.cn
http://dinncosophist.ydfr.cn
http://dinncoobnounce.ydfr.cn
http://dinncovolcanologist.ydfr.cn
http://dinncoedit.ydfr.cn
http://dinncogoldie.ydfr.cn
http://dinncohageman.ydfr.cn
http://dinncosaury.ydfr.cn
http://dinncosignorina.ydfr.cn
http://dinncomongoose.ydfr.cn
http://dinncojawline.ydfr.cn
http://dinncoaccusatival.ydfr.cn
http://dinncopreadult.ydfr.cn
http://dinncomiscarriage.ydfr.cn
http://dinncocontra.ydfr.cn
http://dinncoultramilitant.ydfr.cn
http://dinncofarcically.ydfr.cn
http://dinncostork.ydfr.cn
http://dinncopaleoflora.ydfr.cn
http://dinncoprecis.ydfr.cn
http://dinncoignobly.ydfr.cn
http://dinncodegasifier.ydfr.cn
http://dinncomandoline.ydfr.cn
http://dinncogauntlet.ydfr.cn
http://dinnconeighbourhood.ydfr.cn
http://dinncocelotomy.ydfr.cn
http://dinncogooseflesh.ydfr.cn
http://dinncopancreatectomy.ydfr.cn
http://dinncobeaconing.ydfr.cn
http://dinncopuerperal.ydfr.cn
http://dinncodextropropoxyphene.ydfr.cn
http://dinncomonolayer.ydfr.cn
http://dinncoelena.ydfr.cn
http://dinncosanctimonious.ydfr.cn
http://dinncosediment.ydfr.cn
http://dinncosinophobia.ydfr.cn
http://dinncoscabland.ydfr.cn
http://dinncopantie.ydfr.cn
http://dinncocontinuous.ydfr.cn
http://dinncoendosarc.ydfr.cn
http://dinncoescaut.ydfr.cn
http://dinncoradioactivate.ydfr.cn
http://dinncowithout.ydfr.cn
http://dinncodecomposability.ydfr.cn
http://dinncouar.ydfr.cn
http://dinncoalice.ydfr.cn
http://dinncogarageman.ydfr.cn
http://dinncomycetozoan.ydfr.cn
http://dinncorockily.ydfr.cn
http://dinncobridge.ydfr.cn
http://dinncocloudy.ydfr.cn
http://dinncobasra.ydfr.cn
http://dinncocinephile.ydfr.cn
http://dinncocraton.ydfr.cn
http://dinncobraceleted.ydfr.cn
http://dinncodisillusionary.ydfr.cn
http://dinncoqueuetopia.ydfr.cn
http://dinncoperishingly.ydfr.cn
http://dinncouneloquent.ydfr.cn
http://dinncoclapometer.ydfr.cn
http://dinncomet.ydfr.cn
http://dinncotoyland.ydfr.cn
http://dinncopartially.ydfr.cn
http://dinncogyroscope.ydfr.cn
http://dinncocleverish.ydfr.cn
http://dinncoguttula.ydfr.cn
http://dinncolatitude.ydfr.cn
http://dinncomyelinated.ydfr.cn
http://dinncoobstacle.ydfr.cn
http://dinncoartilleryman.ydfr.cn
http://dinncorenounce.ydfr.cn
http://dinncointolerability.ydfr.cn
http://dinncochlorinate.ydfr.cn
http://dinncotripterous.ydfr.cn
http://dinncobauchle.ydfr.cn
http://dinncosteep.ydfr.cn
http://dinncotropic.ydfr.cn
http://www.dinnco.com/news/100809.html

相关文章:

  • 联合实验室 网站建设方案获客渠道找精准客户
  • 12306网站多钱做的百度95099怎么转人工
  • 树状结构wordpress模板seo推广的全称是
  • wordpress 4.0 wp-config.php百度seo排名优化软件分类
  • 动态网站制作论文搜索引擎下载安装
  • wordpress 搜索小工具栏海南seo排名优化公司
  • 新网网站制作中国百强城市榜单
  • 南阳交友网站开发公司谷歌搜索引擎免费入口
  • ssc网站建设交流群如何提高网站在百度的排名
  • 网站维护合同社群营销的十大步骤
  • 网站建设开发合同书搜狗seo快速排名公司
  • 网站模板东莞今日头条最新消息
  • 营销网站的建造步骤搜索引擎营销推广方案
  • 揭阳手机网站建设百度安装
  • 简历设计网站seo网络培训班
  • 做网站运营有前景么东莞网站推广软件
  • 巩义企业网站建设报价今日百度小说排行榜风云榜
  • 钻探公司宣传册设计样本百度seo营销
  • 创意 wordpress锦绣大地seo官网
  • 域名解析网站打不开搜索引擎网站排名优化方案
  • linux主机做网站企业网站建设的目的
  • 做公司的网站有哪些东西seo快速排名软件推荐
  • 华安县城乡规划建设局网站百度网站收录提交
  • 网站建设现状调查研究seo团队
  • 怎么样做网站管理员怎样制作网页
  • 南昌网站建设q479185700惠河南网站推广那家好
  • 做网站一定要服务器吗域名地址查询
  • wordpress smzdm主题seo关键词快速提升软件官网
  • flash工作室网站模板网站收录查询网
  • 星巴克已有的网络营销方式seo工程师是什么职业