Pattern > Créateurs

Pattern > Structuraux

Pattern > Comportementaux

Références

L'actualité

Librairie

L'information

Design pattern > Comportementaux > Iterator

Ce patron permet d'accéder séquentiellement aux éléments d'un ensemble sans connaitre les détails techniques du fonctionnement de l'ensemble. C'est un des patrons les plus simples et les plus fréquents. Selon la spécification originale, il consiste en une interface qui fournit les méthodes Next et Current. L'interface en Java comporte généralement une méthode nextElement et une méthode hasMoreElements


Iterator (AbstractIterator)
  • defines an interface for accessing and traversing elements.
ConcreteIterator (Iterator)
  • implements the Iterator interface.
  • keeps track of the current position in the traversal of the aggregate.
Aggregate (AbstractCollection)
  • defines an interface for creating an Iterator object
ConcreteAggregate (Collection)
  • implements the Iterator creation interface to return an instance of the proper ConcreteIterator
			
Iterating over collection:
Item 0
Item 2
Item 4
Item 6
Item 8