迭代子模式(Iterator)学习

文章作者 100test 发表时间 2007:10:15 12:10:57
来源 100Test.Com百考试题网



看下面的代码学习JAVA迭代子模式(Iterator)的使用方法
public abstract class Aggregate
{
public abstract Iterator createIterator().
}

public interface Iterator
{
void first().
void next().
boolean isDone().
Object currentItem().
}

public class ConcreteAggregate extends Aggregate
{
private Object[] objs={"Monk Tang","Monkey","Pigsy","Sandy","Horse"}.
public Iterator createIterator()
{
return new ConcreteIterator().
}
private class ConcreteIterator implements Iterator
{
private int currentIndex=0.
public void first()
{
currentIndex=0.
}
public void next()
{
if(currentIndex {
currentIndex .
}
}
public boolean isDone()
{
return (currentIndex>=objs.length).
}
public Object currentItem()
{
return objs[currentIndex].
}
}
}

public class Client
{
private Iterator it.
private Aggregate agg=new ConcreteAggregate()
public void operation()
{
it=agg.createIterator().
while(!it.isDone())
{
System.out.println(it.currentItem().toString()).
it.next().
}

相关文章


迭代子模式(Iterator)学习
专业语言:Java编程命名规范
正则--[]的使用方法
命令模式(Command)讲解
Java中SOAP技术应用学习
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛