© Vaskaran Sarcar 2020
V. SarcarDesign Patterns in C#https://doi.org/10.1007/978-1-4842-6062-3_18

18. Iterator Pattern

Vaskaran Sarcar1 
(1)
Garia, Kolkata, West Bengal, India
 

This chapter covers the Iterator pattern.

GoF Definition

Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

Concept

Iterators are generally used to traverse a container (or a collection of objects) to access its elements without knowing how the data are stored internally. It is very useful when you need to traverse different kinds of collection objects in a standard and uniform way. Figure 18-1 shows a sample and most common diagram for an Iterator pattern.
Figure 18-1

A sample diagram for an Iterator pattern

The ...

Get Design Patterns in C#: A Hands-on Guide with Real-world Examples now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.