Iterator Design Pattern

[ad_1]
Get the Code:

Welcome to my Iterator Design Pattern Tutorial! The iterator design pattern allows you to access objects that are stored in many different collection types.

You do this by creating a common interface that these classes share. Then you have them provide you with an iterator that allows you to traverse the objects they contain.

Because they all share a common interface you can treat them polymorphically and eliminate a lot of duplicate code.


Posted

in

by

Tags:

Comments

39 responses to “Iterator Design Pattern”

  1. Talha Zia Avatar

    Why not make 1 SongIterator for all 3 objects?

  2. Talha Zia Avatar

    Brilliant video, I have a question, a very basic one, what difference does removing/adding "@override" annotation makes here when we implement SongIterator interface?

  3. Nick Gundobin Avatar

    good tutorials, but your voice makes them unwatchable. sorry

  4. ҉K҉N҉ I҉G҉HT҉F҉ I҉ ҉R҉Ế҉6҉6҉ Avatar

    do someone understand 13:22 what does he do there? i cant type in the same in my programm…

  5. devnand Avatar

    I am a big fan of your videos, but this video does NOT teach the iterator pattern , rather it uses the existing java's Iterator. Looks more like an application of the Adapter pattern.

    The video should have defined an Itertator interface and made all the Song lists implement that iterator interface.

  6. hilton hacks Avatar

    Subscribed 🙂 ! best tutorial seen so far!

  7. 25500X Avatar

    what a horrible voice

  8. Tritone Avatar

    hmmm…how does the Iterator Pattern actually work? It would have been better if you showed how to implement one instead of using the API.

  9. milo molo Avatar

    cool video, dude. u explain better than my professor

  10. Fabio Esposito Avatar

    Hello,
    Good video, but it would have been great to show that you can type your iterator.
    And also mentionning that it is very useful to go through a list and at the same time removing some elements, without getting a ConcurrentModificationException 🙂

  11. 呀明 Avatar

    Easy and good explanation of design patterns , covers from beginner to novices.
    Hey you earned a subscriber.

  12. Pushkaraj Patil Avatar

    Hello Derek,
    Thank you for this video, I was trying to implement this pattern using C++ (STL) , but I am facing issues. The main reason what I am observing is, in STL, there is no single base class for different containers (vectors, maps, deque etc) iterators. So I am unable to implement a common function to iterate through all containers using same iterator type and ending up in writing different print functions for different containers. Could you please suggest any work around for this problem in C++

  13. Antoni Szewczyk Avatar

    What is the advantage of implementing iterator pattern if I simply can retrieve Iterator object from the list?
    Let's say I have LinkedList called birds so I can do:

    Iterator<String> iterator = birds.iterator()

    and then I am able to use functions like hasNext() or any other?

  14. Moussa Traore Avatar

    I don't understand why you have to cast the return value of Iterator.next() .. is it not already a SongInfo object ?

  15. Global S Avatar

    +Derek Banas, I have seen your other video which was all great. but i think in this code you have written for explaining iterator is not complete. because you didn't create iterator from the scratch like other design pattern video you did. thus its confusing.

  16. Andrew Daly Avatar

    Why Hashtable<Integer, SongInfo> and not Hashtable<int, SongInfo> ?

  17. Sahar Mu. Avatar

    thank you <3 subscribed !!!

  18. K Badsha Avatar

    I was a bit confused. How did you make objects from an interface ? :/

  19. davix Avatar

    hello Derek,
    It's Davix again. I want to know do you have a tutorial about shallow and deep cloning in java? Thx !

  20. davix Avatar

    hello Derek,
    Thanks for your tutorials, both this one and the UML are my favorite !
    However, when I try to run this code, this error occurred:
    ————————————————
    Exception in thread "main" java.lang.NullPointerException
    at Iterator.DiscJockey.showTheSongs2(DiscJockey.java:66)
    ————————————————
    It's
    Iterator Songs70s = iter70sSongs.createIterator();

    Do you have any clue to solve it?
    Sorry to trouble and thx again !

  21. Raul Zuniga Avatar

    We didn't go over iterators in my data structures class I just took. I know what they were but didn't realize how useful they can be until now. Well worth the time to show us a good way and a better way.  Props to you!

  22. Rupali Pawaskar Avatar

    Hello Derek,

    I liked your video. would we please recommend some books to learn design patterns in detail along with some good implementation for each on of it.
    Thanks for the video again.

  23. Vasupol CHATMETHAKUL Avatar

    should i still buy the book even after your tutorial?

  24. Bijoy Baral Avatar

    Hi Derek,

    Fantastic explanation :), thank you ..

  25. PRATIK RAJPUT Avatar

    that was awesome code man thanks it helped me

  26. Gracia Rivas Avatar

    This is just the best youtube tutorial I have ever seen. 

  27. Mohsen Moeini Avatar

    Really useful video, Thank you.But i couldn't download your full presentation from Drop Box, if it is possible share it for me.thanks again .

  28. Kyle Nunweiler Avatar

    Great explanation! Thanks a lot.

  29. Thabo Teffu Avatar

    Thank you for your videos, I watched all of them and they really helped me understand design patterns.

  30. Gabriel Menachem Avatar

    Nice1 saved me 150+ lines of code & a Sandwich.

  31. wjrasmussen666 Avatar

    Hey Derek,
    What is the best way to get rid of the type warnings on the iterators?

  32. Ernani Mattos Avatar

    I use your videos as reference to remember stuff, witch is excellent. If I have to learn more details stuff, actually I go read a book about it, and these videos really help to make things clear. Keep up de good work. 

  33. Antonia Ivanova Avatar

    I understand you're very good at making videos but I feel like you need 2 critics if you indeed want to TEACH people something and not just show them how its done. Your explanation is way too brief and really directed towards your current example. Maybe say why this is useful when to use it how it overall should be written.. stuff like that. And 2nd of all you do this too fast

    tldr : I dont feel like I learnt something, i feel like I learnt this exact example..

  34. Julio Romano Avatar

    nice! congrats from Brazil

  35. Derek Banas Avatar

    Thank you 🙂 You're very welcome.

  36. Despendo Avatar

    Woaaaw very interesting video ! I'm a french studients and now, with your tutorial, I understand better this DP ! Thanks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *