package com.tn.pattern;

 public class Client {
public static void main(String[] args) {
Object[] objs={"飞","雪","连","天","射","白","鹿","笑","书","神"};
Aggregate aggregate=new ConcreteAggregate(objs); Iterator it=aggregate.iterator();
it.first();
it.next();
System.out.println(it.isDone());
it.currentItem(); it.first();
System.out.println("----------------------------------------");
while(!it.isDone()){
it.currentItem();
it.next();
}
}
} interface Iterator{
void first();
void next();
boolean isDone();
void currentItem();
} interface Aggregate{
Iterator iterator();
} class ConcreteAggregate implements Aggregate{
private Object[] datas=new Object[10]; public ConcreteAggregate(Object[] objs){
this.datas=objs;
} public Iterator iterator(){
return new ConcreteIterator();
} class ConcreteIterator implements Iterator{
private int index;
@Override
public void first() {
index=0;
}
@Override
public void next() {
index++;
}
@Override
public boolean isDone() {
return index>=datas.length;
}
@Override
public void currentItem() {
if(index<datas.length)
System.out.println(datas[index]);
}
}
}