C# CONCEPTS
Design Pattern - Iterator
According to Gang of Four, the iterator pattern provides a process to obtain the aggregator object without knowing its implementation.
Use Case
Let us take an example of a collection list
of cars and string[]
an array of motorcycles, we need to design an aggregator object so that one can iterate over the collection without knowing whether it's a list
or an array
.
The iterator design pattern helps solve this problem wherein a standard iterator will traverse different collection types.
Prerequisites
- Basic knowledge of OOPS concepts.
- Any programming language knowledge.
The article demonstrates the usage of iterator design patterns using the C# programming language. So, to begin with, C#
Getting Started
Considering the above use case, let us define a custom iterator interface that…