迭代器模式
一、题目:
某教务管理信息系统中,一个班级(class)包含多个学生(Stedent),使用java内置迭代器实现对学生数据的双向遍历,要求按学生年龄由大到小的次序输出学生信息,现使用迭代器模式设计系统。
(1)绘制迭代器模式结构视图
(2)给出实例类图并实现代码。
二、所用模式结构视图:
三、实例类图:
四、实例实现代码:
(因为区分,所以在类的前面加了Gj19)
学生类:
package gjIteratorPattern;
public class Gj19Student implements Comparable<Gj19Student>{
private String name;
private int age;
public Gj19Student(String name, int age) {
super();
this.name = name;
this.age = age;
}
public int compareTo(Gj19Student stu){