迭代器模式(Iterator Pattern)
提供一种方法顺序访问一个聚合对象中各个元素,而又不需暴露该对象的内部表示
JDK中java.util.Iterator就运用了迭代器模式
public interface Iterator<E> {
/**
* Returns {@code true} if the iteration has more elements.
* (In other words, returns {@code true} if {@link #next} would
* return an element rather than throwing an exception.)
*
* @return {@code true} if the iteration has more elements
*/
boolean hasNext();
/**
* Returns the next element in the iteration.
*
* @return the next element in the iteration
* @throws NoSuchElementException if the iteration has no more elements
*/
E next();
/**
* Removes from the underlying collection the last element returned
* by this iterator (optional operation). This method can be called
* only once per call to {@link #next}. The behavior of an iterator
* is unspecified if the underlying collection is modified while the
* iteration is in progress in any way other than by calling this
* method.
*
* @throws UnsupportedOperationException if the {@code remove}
* operation is not supported by this iterator
*
* @throws IllegalStateException if the {@code next} method has not
* yet been called, or the {@code remove} method has already
* been called after the last call to the {@code next}
* method
*/
void remove();
}
分享到:
相关推荐
java常用设计模式-迭代器模式
设计模式-迭代器模式(讲解及其实现代码)
设计模式--迭代器模式java例子
java设计模式--迭代器模式,理解这个例子就完全理解迭代器啦
设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是众多软件开发人员经过相当长的一段...
JAVA-设计模式-行为型模式-迭代器模式
c++设计模式-行为型模式-迭代器模式;qt工程;c++简单源码;迭代器(Iterator)模式的定义:提供一个对象来顺序访问聚合对象中的一系列数据,而不暴露聚合对象的内部表示。
博文“设计模式之--迭代器模式”附属源码,以供参考。
cpp代码-设计模式-迭代器模式
迭代器模式(Iterator Pattern)是一种非常常用的设计模式,这种模式用于顺序访问集合对象的元素,不需要知道集合对象的底层表示。迭代器模式属于行为型模式。 介绍 意图: 提供一种方法顺序访问一个聚合对象中各个...
设计模式之迭代器模式 设计模式之迭代器模式 设计模式之迭代器模式
设计模式专题之(二十三)迭代器模式---设计模式迭代器模式示例代码(python--c++)
23种设计模式之迭代器模式对迭代器模式进行了简单的介绍,并附带了例子程序,和大家分享
设计模式之迭代器模式(新) 设计模式之迭代器模式(新)
这份文档以例子的形式讲诉了设计模式之迭代器与组合模式,希望可以帮助学习的人!