Personal Blog

Personal Blog

Iterator Design Pattern

Iterator Design Pattern

Subscribe to my newsletter and never miss my upcoming articles

Iterator design pattern falls into the category of behavioral pattern. Iterator pattern is used to provide iteration structure to traverse the sequential elements of objects. In collections, the iterator interface provides the methods to traverse the elements of the collection.

According to GoF, iterator provides a way to traverse the elements of an aggregate object without exposing their underlying implementation to the client.

Based on our requirements, we can implement a different kind of iterator. It is not only for traversing purposes. In collections, the iterator hides the actual implementation of traversal and provides only methods for the client to use.

In conclusion, it can be assumed that:

  • Iterator pattern is useful when you want to provide a standard way to iterate over a collection and hide the implementation logic from the client program.

  • The logic for iteration is embedded in the collection itself and it helps the client program to iterate over them easily.

You can find the java implementation of iterator in my github here.

Thank you for reading!

 
Share this