设计技巧37:利用迭代器访问集合内部元素

来源:互联网 发布:轮显源码 编辑:程序博客网 时间:2024/05/21 14:47

提供了外部访问集合的方法,而又不暴漏元素内部细节


Interface Iterator{//迭代器接口

object next();

boolean remove();

boolean hasNext();

}


public class Collection{//被迭代和观察的集合

IteratorClas[]  obs;

get Iterator(){

return new 

}

public class IteratorClas{//被观察的对象

do();

}


public class ConcretIterato implements Iterator{//具体迭代器实现

Collection collection ;

private int index;

public ConcretIterato(Collection c){

collection = c;

}

public  object next(){

return c[++index];

}


public boolean hasNext()}

return indext== c.length;

}

public looean remove{

}


0 0