Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterator design pattern?

Edited for Clarity

I was following a set of tutorial videos on design patterns that use Java to demonstrate various pattern uses, but when I got to the video titled "The Iterator Design Pattern" it just seemed to use a standard Java iterator. I have used iterators in Java before, but was never taught them as a "design pattern." Is there a difference between using an iterator in Java and using the "iterator design pattern"? If so, what is the distinction?

like image 864
Kvass Avatar asked Jun 15 '26 05:06

Kvass


1 Answers

The iterators you have used in Java actually implement the Iterator design pattern. They do:

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

As you can see in the documentation of the Iterable interface in Java, most of the containers you know supply an Iterator object used to:

access their elements sequentially without exposing their underlying representation.

like image 189
stan0 Avatar answered Jun 17 '26 17:06

stan0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!