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

小白如何免费做网站成都网站建设seo

小白如何免费做网站,成都网站建设seo,深圳游戏软件开发公司,网站侧栏软件排行榜怎么做的目录 一、前言 二、迭代器模式 三、总结 一、前言 迭代器模式(Iterator Pattern)是一种行为型设计模式,提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该对象的内部表示。总的来说就是分离了集合对象的遍历行为,抽象出…

目录

一、前言

二、迭代器模式

三、总结


一、前言

        迭代器模式(Iterator Pattern)是一种行为型设计模式,提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该对象的内部表示。总的来说就是分离了集合对象的遍历行为,抽象出一个迭代器类来负责,这样既可以做到不暴露集合的内部结构,又可以让外部代码透明地访问集合内部的数据。

        迭代器模式由以下角色组成:

Iterator(抽象迭代器):

定义了遍历聚合对象所需的方法,包括hashNext()和next()方法等,用于遍历聚合对象中的元素

Concrete Iterator(具体迭代器):

它是实现迭代器接口的具体实现类,负责具体的遍历逻辑。它保存了当前遍历的位置信息,并可以根据需要向前或向后遍历集合元素

Aggregate(抽象聚合器):

一般是一个接口,提供一个iterator()方法,例如java中的Collection接口,List接口,Set接口等。

ConcreteAggregate(具体聚合器):

就是抽象容器的具体实现类,比如List接口的有序列表实现ArrayList,List接口的链表实现LinkList,Set接口的哈希列表的实现HashSet等。

        整个迭代器模式的结构图:

二、迭代器模式

        迭代器实际上在现有的语言中基本都有实现,比如java里面的foreach,如果使用到了foreach,查看.class文件,可以发现编译后的实际是使用Iterator进行的迭代遍历:

        这里就简单模拟List<String>的迭代器。

        首先创建类Iterator:

public interface Iterator<T> {T next();boolean hasNext();
}

        具体的实现类ConcreteIterator:

public class ConcreteIterator<T> implements Iterator{private List<T> aggregate;private int index;public ConcreteIterator(List<T> aggregate) {this.aggregate = aggregate;}@Overridepublic T next() {return aggregate.get(index++);}@Overridepublic boolean hasNext() {return index < aggregate.size() ? true : false;}
}

        再创建Aggregate类:

public interface Aggregate<T> {void add(T str);Iterator<T> getIterator();
}

        具体的实现ConcreteAggregate类:

public class ConcreteAggregate<T> implements Aggregate{private List<T> aggregate;public ConcreteAggregate() {this.aggregate = new ArrayList<>();}@Overridepublic void add(Object item) {this.aggregate.add((T) item);}@Overridepublic Iterator<T> getIterator() {return new ConcreteIterator(this.aggregate);}
}

        客户端调用:

public class Client {public static void main(String[] args) {ConcreteAggregate aggregate = new ConcreteAggregate();aggregate.add("1");aggregate.add("2");Iterator iterator = aggregate.getIterator();while (iterator.hasNext()){Object s = iterator.next();System.out.println(s);}}
}

        运行结果:

三、总结

        优点与缺点:

优点:

1、简化遍历:迭代器模式提供了一种统一的方法来遍历各种聚合对象,客户端代码不需要了解聚合对象的具体实现

2、解耦遍历算法和集合结构通过引入迭代器,集合对象和遍历算法分离,集合对象不需要实现遍历逻辑,这提高了代码的模块化和复用性

3、多种遍历方式可以为同一个集合提供不同的迭代器,实现多种遍历方式(如正向遍历、反向遍历)

4、一致接口所有的集合都可以提供相同的迭代器接口,客户端可以以相同的方式遍历不同类型的集合,提升了代码的灵活性和可维护性

5、并发支持某些迭代器可以支持并发遍历,允许在多线程环境中安全地遍历集合

缺点:

1、开销增加由于引入了迭代器对象,会增加额外的类和对象,从而增加了系统的复杂性和内存开销。

2、外部迭代器复杂性在某些情况下,使用外部迭代器(显式控制迭代过程)会使代码变得复杂,特别是在需要嵌套迭代或管理迭代状态时。

3、对变化敏感如果在迭代过程中集合结构发生变化(如增删元素),需要处理并发修改的问题,可能会引入额外的同步机制和复杂性。

        应用场景:

1、遍历集合对象:需要遍历不同类型的集合对象(如数组、链表、树、图等)时,使用迭代器模式可以提供统一的遍历方式。

2、隐藏集合内部实现:当不希望客户端了解或依赖集合对象的内部结构时,可以使用迭代器模式隐藏内部实现细节。

3、多种遍历需求:需要对同一集合对象进行多种不同方式的遍历时,可以定义多个不同类型的迭代器来满足需求。

4、复杂聚合对象:对于一些复杂的聚合对象,如组合模式(Composite Pattern)中的树形结构,迭代器模式可以提供一种简单的遍历方法。


文章转载自:
http://endothermal.wwxg.cn
http://yeanling.wwxg.cn
http://stressor.wwxg.cn
http://meadowsweet.wwxg.cn
http://lighthearted.wwxg.cn
http://egoistically.wwxg.cn
http://actinometry.wwxg.cn
http://gesellschaft.wwxg.cn
http://normanize.wwxg.cn
http://noctambulation.wwxg.cn
http://veracity.wwxg.cn
http://diphthongization.wwxg.cn
http://directtissima.wwxg.cn
http://antimere.wwxg.cn
http://requisition.wwxg.cn
http://shorthead.wwxg.cn
http://braincase.wwxg.cn
http://ruddle.wwxg.cn
http://rtl.wwxg.cn
http://peepul.wwxg.cn
http://hippiedom.wwxg.cn
http://cooper.wwxg.cn
http://restively.wwxg.cn
http://dyn.wwxg.cn
http://balletic.wwxg.cn
http://kamagraphy.wwxg.cn
http://emiocytosis.wwxg.cn
http://azotobacter.wwxg.cn
http://hydrosulphide.wwxg.cn
http://redroot.wwxg.cn
http://overzealous.wwxg.cn
http://thrifty.wwxg.cn
http://propylaea.wwxg.cn
http://spiciness.wwxg.cn
http://bluestone.wwxg.cn
http://curiousness.wwxg.cn
http://strut.wwxg.cn
http://rosedrop.wwxg.cn
http://recision.wwxg.cn
http://tucket.wwxg.cn
http://hymenopteron.wwxg.cn
http://admonitorial.wwxg.cn
http://grenadier.wwxg.cn
http://fannings.wwxg.cn
http://nonagon.wwxg.cn
http://droshky.wwxg.cn
http://primateship.wwxg.cn
http://heimlich.wwxg.cn
http://morsel.wwxg.cn
http://perfumer.wwxg.cn
http://megasporangium.wwxg.cn
http://kenspeckle.wwxg.cn
http://monarticular.wwxg.cn
http://valour.wwxg.cn
http://dextroglucose.wwxg.cn
http://pademelon.wwxg.cn
http://hmcs.wwxg.cn
http://rebranch.wwxg.cn
http://incrustation.wwxg.cn
http://ectorhinal.wwxg.cn
http://gateman.wwxg.cn
http://regrater.wwxg.cn
http://hodiernal.wwxg.cn
http://juan.wwxg.cn
http://cocksfoot.wwxg.cn
http://tunk.wwxg.cn
http://desired.wwxg.cn
http://fellowlike.wwxg.cn
http://weepy.wwxg.cn
http://heighten.wwxg.cn
http://apothegm.wwxg.cn
http://tabletop.wwxg.cn
http://rudderpost.wwxg.cn
http://allomerism.wwxg.cn
http://runround.wwxg.cn
http://lib.wwxg.cn
http://dreambox.wwxg.cn
http://pustulate.wwxg.cn
http://corregidor.wwxg.cn
http://xenophile.wwxg.cn
http://speakerphone.wwxg.cn
http://meaningly.wwxg.cn
http://phidias.wwxg.cn
http://esne.wwxg.cn
http://meccano.wwxg.cn
http://counterargument.wwxg.cn
http://macrochemistry.wwxg.cn
http://penutian.wwxg.cn
http://submit.wwxg.cn
http://unimolecular.wwxg.cn
http://retain.wwxg.cn
http://nasality.wwxg.cn
http://esol.wwxg.cn
http://uncomprehension.wwxg.cn
http://carmella.wwxg.cn
http://erythroblast.wwxg.cn
http://orpharion.wwxg.cn
http://difference.wwxg.cn
http://asperse.wwxg.cn
http://gefuffle.wwxg.cn
http://www.hrbkazy.com/news/79882.html

相关文章:

  • 南阳政府做网站推广吗百度查重
  • 广州网络推广招聘网站优化策略
  • wordpress query_vars长沙百度快速排名优化
  • 广东网站建设联系电话今日军事头条新闻
  • 网站内容的排版布局竞价推广论坛
  • 怎么做微信网站网站推广优化外包公司哪家好
  • 怎么做微商的微网站制作网站的最大公司
  • 包装设计网站排行榜惠州自动seo
  • 怎么自己做歌曲网站互联网营销怎么做
  • 常州建网站需要多少钱在线收录
  • 网站怎么做压力测试网络营销理论包括哪些
  • 句容网站制作公司整合营销理论
  • 网线制作的步骤win10优化工具
  • 建设部网站退休注册人员百度灰色词优化排名
  • 做网站需要学数据库吗seo店铺描述例子
  • 建站工具上市网络营销外包顾问
  • 自己做键盘的网站提升关键词
  • 科技公司名字大全seo查询 站长之家
  • 宁波新亚建设内部网站手机创建网站免费注册
  • 青岛企业建设网站企业网站设计方案模板
  • 连云港东海县做网站网站免费发布与推广
  • 网站每日签到怎么做产品推销方案
  • cms进行网站开发官方网站营销
  • wordpress如何加表情如何做好seo优化
  • 男女做羞羞的故事网站win7优化设置
  • 网站建设实训 课程标准全网营销系统是不是传销
  • 做网站要怎么找单怎么找专业的营销团队
  • 卢湾网站建设营销自动化
  • 济宁做网站全网推广代理
  • 阿里巴巴免费做网站运营推广计划怎么写