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

大企业网站建设费用市场调查报告模板及范文

大企业网站建设费用,市场调查报告模板及范文,住房建设部官方网站居住区政策,网上兼职做效果图网站一、介绍: 1、定义:迭代器模式 (Iterator Pattern) 是一种行为型设计模式,它提供一种顺序访问聚合对象(如列表、集合等)中的元素,而无需暴露聚合对象的内部表示。迭代器模式将遍历逻辑封装在一个迭代器对象…

一、介绍:

1、定义:迭代器模式 (Iterator Pattern) 是一种行为型设计模式,它提供一种顺序访问聚合对象(如列表、集合等)中的元素,而无需暴露聚合对象的内部表示。迭代器模式将遍历逻辑封装在一个迭代器对象中,使得我们可以使用统一的方式遍历不同类型的聚合对象,同时也可以简化客户端代码。

2、组成:

(1)抽象聚合 (Aggregate) :定义存储、添加、删除聚合元素以及创建迭代器对象的接口。
(2)具体聚合 (ConcreteAggregate) :实现抽象聚合类,返回一个具体迭代器的实例。
(3)抽象迭代器 (Iterator) :定义访问和遍历聚合元素的接口,通常包含 hasNext()、next() 等方法。
(4)具体迭代器 (Concretelterator) :实现抽象迭代器接口中所定义的方法,完成对聚合对象的遍历,记录遍历的当前位置。

二、demo:

1、

package com.demo.ddq.dto;public class Student {private String name;private String number;public Student() {}public Student(String name, String number) {this.name = name;this.number = number;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", number='" + number + '\'' +'}';}/**省略所有set、get方法*/
}

(1)抽象迭代器

//抽象迭代器角色接口
public interface StudentIterator {//判断是否还有元素boolean hasNext();//获取下一个元素Student next();
}

(2)具体迭代器

//具体迭代器角色类
public class StudentIteratorImpl implements StudentIterator{private List<Student> list;//用来记录遍历时的位置private int position = 0;public StudentIteratorImpl(List<Student> list) {this.list = list;}@Overridepublic boolean hasNext() {return position < list.size();}@Overridepublic Student next() {//从集合中或者去指定位置的元素Student currentStudent = list.get(position);position++;return currentStudent;}
}

(3)抽象聚合:

//抽象聚合(容器)角色接口
public interface StudentAggregate {//添加学生void addStudent(Student stu);//删除学生void removeStudent(Student stu);//获取迭代器对象StudentIterator getStudentIterator();
}

(4)具体聚合:

public class StudentAggregateImpl implements StudentAggregate{private List<Student> list = new ArrayList<>();@Overridepublic void addStudent(Student stu) {list.add(stu);}@Overridepublic void removeStudent(Student stu) {list.remove(stu);}//获取迭代器对象@Overridepublic StudentIterator getStudentIterator() {return new StudentIteratorImpl(list);}
}

客户端:

public class Test {public static void main(String[] args) {//创建聚合(容器)对象StudentAggregate aggregate = new StudentAggregateImpl();Student student1 = new Student("张三", "1001");Student student2 = new Student("李四", "1002");Student student3 = new Student("王五", "1003");Student student4 = new Student("钱七", "1004");//添加元素aggregate.addStudent(student1);aggregate.addStudent(student2);aggregate.addStudent(student3);aggregate.addStudent(student4);//删除元素aggregate.removeStudent(student3);//遍历聚合对象// 1.获取迭代器对象StudentIterator iterator = aggregate.getStudentIterator();// 2.遍历while (iterator.hasNext()) {// 3.获取元素Student student = iterator.next();System.out.println(student.toString());}}
}输出:
Student{name='张三', number='1001'}
Student{name='李四', number='1002'}
Student{name='钱七', number='1004'}

http://www.dt0577.cn/news/3294.html

相关文章:

  • 沈阳优化网站长春网站优化
  • 那里可以做app网站东莞哪种网站推广好
  • 网站seo具体怎么做关键词排名的工具
  • 网站首页banner怎么做0元做游戏代理
  • 唐山做网站公司哪家好如何在百度上开店铺
  • 门户网站开发流程浙江seo技术培训
  • 美篇相册制作免费下载app黑帽seo工具
  • 电子商务企业网站的基本功能原创代写文章平台
  • 南宁网站 制作seo快速排名软件平台
  • 中企动力做的网站升级收费sem是什么岗位
  • 欧美做愛网站A级移动惠生活app下载网址
  • 南京网站开发价格东莞网站seo推广
  • 做调查问卷换赏金的网站新冠病毒最新消息
  • wordpress默认页面黄石seo
  • 静态后台管理网站模板班级优化大师下载
  • 珠江摩尔网站建设电商平台推广
  • 哪个网站做淘宝客国外seo工具
  • 济南网站建设优化怎么做电商卖东西
  • 谁有好的网站推荐一个网站推广平台搭建
  • 建设部网站冯耀宗seo教程
  • wordpress代码片段南宁网站seo
  • 如何把网站程序做授权网址访问网站建立具体步骤是
  • 地方旅游网站模板一键制作免费网站的app
  • 重庆市建筑工程信息网官网优化网站排名的方法
  • wordpress模版侵权兰州网络推广关键词优化
  • 国家重点项目建设部网站网络营销机构官方网站
  • 网站能实现什么功能深圳网络营销平台
  • 做vr网站地推app
  • 做营销型网站公司杭州seo排名
  • wordpress单页面网站怎么做百度热度