Iterator Design Pattern

Поділитися
Вставка
  • Опубліковано 29 гру 2024

КОМЕНТАРІ •

  • @derekbanas
    @derekbanas  12 років тому +2

    That is high praise! I can't think of many people who could drive people to action like John Lennon did. Thank you SawMan :)

  • @raulzuniga4382
    @raulzuniga4382 9 років тому +1

    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!

  • @stefan4800
    @stefan4800 6 років тому

    If you have fundamentals under your feet, Derek Banas is the best teacher ever. But if you don't, these videos are the real pain. I'm glad I can watch these videos today with a joy.

  • @vbnandu867
    @vbnandu867 7 років тому +58

    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.

  • @1988fearless
    @1988fearless 11 років тому

    thank you so much buddy for the videos you saved me from my prof video which is useless 2 hours with a 22 mins full of knowledge , i really appreciate your work my friend

  • @nais0000
    @nais0000 11 років тому

    I never get tired of liking your video.

  • @ljka
    @ljka 4 роки тому +9

    It's 2020 in the middle of a pandemic. Got nothing to do so im rewatching the whole playlist 😂

  • @derekbanas
    @derekbanas  12 років тому +1

    The thing with design patterns is that people tend to never use them, or they over use them. Are they valuable? I'd say they definitely are if only to make systems easier to describe to others. When you work on a large project meaning thousands of lines of code you'll see the value in describing 15 lines of code with a pattern name. On top of that, your code will be very readable by others that know patterns

  • @derekbanas
    @derekbanas  12 років тому

    The patterns provide coding perfection! It just takes a bit to get there

  • @derekbanas
    @derekbanas  12 років тому +1

    Thank you :) I do my best to fill in the niche subjects that others don't. I'll be covering every Java framework by the end. I'm working on a code refactoring tutorial that is getting quite large, so you can see I'll be covering Java at a deep level. I also have tutorials on graphics engines created in combination with c in the works. Everything J2EE will be covered along with everything else you guys ask for. Thanks for the request

  • @derekbanas
    @derekbanas  11 років тому

    I'm very happy to be of help :) I wish you the best of luck on your interviews and new job.

  • @TheDespendo
    @TheDespendo 11 років тому

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

  • @derekbanas
    @derekbanas  11 років тому

    Thank you :) I'm very happy to cover these niche topics

  • @gytautebarzdziute7358
    @gytautebarzdziute7358 3 роки тому

    Thank you a lot. It is the best tutorial I have ever watched.

    • @derekbanas
      @derekbanas  3 роки тому

      Thank you very much :) I'm happy you liked it

  • @avdhootjadhav6705
    @avdhootjadhav6705 Рік тому

    Derek it was a good watch. I felt this is amazing pattern. Hope to learn more patterns from your videos

  • @derekbanas
    @derekbanas  12 років тому

    A link to the source code is in the description for the video. I hope it helps and feel free to ask questions

  • @derekbanas
    @derekbanas  11 років тому

    I'm going to cover algorithms and data structures again soon. Sorry i can't make the video now

  • @derekbanas
    @derekbanas  11 років тому

    Thank you :) That is very nice of you to say that

  • @Tritone
    @Tritone 8 років тому +30

    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.

    • @user-baev
      @user-baev 7 років тому

      Yea, kinda bad approach. Iterator is one of the most used patterns and is really useful to understand how it works.

    • @ppraisethesun
      @ppraisethesun 7 років тому +4

      Can't you just go into the sources of iterator class?

    • @smartwerker
      @smartwerker 5 років тому +1

      @@ppraisethesun ikr. Seriously ppl want everything handed to them

    • @IamQuuick
      @IamQuuick 5 років тому +3

      @@smartwerker I mean it's a tutorial, how is it weird that people want to learn how it actually works by clicking on this video?

  • @AnsonChik
    @AnsonChik 8 років тому

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

  • @Krishna-vn3zx
    @Krishna-vn3zx 6 років тому

    Good video. The pragmatic approach to implementing java iterator interface step by step was exceptional + advice on good coding practices was well-received.

  • @derekbanas
    @derekbanas  11 років тому

    Thank you very much for the kind message :) You're very welcome

  • @derekbanas
    @derekbanas  12 років тому

    You're very welcome :) I'm glad to have helped

  • @gosnooky
    @gosnooky 5 років тому

    21:38 - why didn't you type the Iterator as Iterator? Then you don't have to cast.

  • @Knightfire66
    @Knightfire66 7 років тому

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

  • @ErnaniMattosJr
    @ErnaniMattosJr 11 років тому

    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.

    • @derekbanas
      @derekbanas  11 років тому +1

      Thank you very much :) I always considered my videos to be a good addition to either book or classroom study.

  • @tomyang7788
    @tomyang7788 7 років тому

    at 6:14 bestSongs[arrayValue] = song , song is undefined ?

  • @aaronaaronaaron5922
    @aaronaaronaaron5922 3 роки тому

    What awesome channel!!! 🤯 Thanks!!!!

  • @milomolo7702
    @milomolo7702 8 років тому

    cool video, dude. u explain better than my professor

    • @derekbanas
      @derekbanas  8 років тому +1

      Thank you :) It is very nice of you to say that

  • @derekbanas
    @derekbanas  11 років тому

    You're very welcome :) I do the best that I can

  • @logs
    @logs 6 років тому +1

    It's unfortunate that you didn't provide an UML with it to explain the specific classes that you've made and put it side by side to show what class is what in the UML structure of a valid Iterator pattern structure.

  • @arunsasidharannambiar
    @arunsasidharannambiar 11 років тому

    Thanks! Your videos have really helped me prepare for interviews!

  • @globalsoftwarearchitects1769
    @globalsoftwarearchitects1769 9 років тому +2

    +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.

    • @derekbanas
      @derekbanas  9 років тому

      +Global S Sorry about that. I hope to revisit design patterns.

  • @thaboteffu2170
    @thaboteffu2170 10 років тому

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

    • @derekbanas
      @derekbanas  10 років тому

      Thabo Teffu You're very welcome :) I'm glad I could help

  • @felixmerz00
    @felixmerz00 2 роки тому

    What if I want to iterate over the elements of a nested ArrayList.
    E.g. I have an ArrayList that I call "names" and I want to iterate over the strings. With your solution the createIterator() method would return names.iterator() which would be an interator which iterates over ArrayList objects. But I want to iterate over the strings itself, not over the ArrayLists which contain the strings. Can this be solved?

  • @lindaecho-hawk574
    @lindaecho-hawk574 11 років тому

    Thank you for the very clear explanation of the iterator pattern!

  • @derekbanas
    @derekbanas  11 років тому

    Thank you :) yes, I should have used more diagrams.

  • @godzabomni4148
    @godzabomni4148 4 роки тому

    What if i want the array to be dynamic? There you said size is 3, what if I want size 50 but there's some empty spots?

  • @curiossoul
    @curiossoul 2 роки тому

    I didnt get you why implemented Iterator interface and then return java list.iterator from SongOf80s etc classes. Shouldn't you be returning SongIterator implemenation instance instead ?

  • @kanghojoo6420
    @kanghojoo6420 6 років тому

    to Tritone
    as you see the keyword "implement" from the video, the iterator is a kind of interface. so you can check what kind of method in this awesome interface for the collections. of course in the java API page in the oracle website(or sunMicros or whatever lol)

  • @kickingpinay
    @kickingpinay 12 років тому

    finally, i understand why i need to use an iterator :P. Thanks!

  • @sealwithawkwardness3951
    @sealwithawkwardness3951 5 років тому

    I don't actually think it has to do with a COLLECTION of objects rather it's just a way to access and cycle to the next item in a SEQUENCE.
    For example, you can have an iterator to go through the Fibonacci sequence and all the iterator does it give you the next number in the sequence. For example if you begin with 1, when you call next on that iterator you get 1, call next again and you get 2 and so on and so forth. The actual sequence doesn't need to be in a collection but it could, it rather abstracts a way to get items in sequence.

  • @derekbanas
    @derekbanas  11 років тому

    Thank you :) You're very welcome.

  • @SRISHONLINE
    @SRISHONLINE 7 років тому

    +Derek Banas : concept wise clear, but transformation into C++ is not easy through with the given sample. Any suggestions?

  • @PerfectHilton
    @PerfectHilton 8 років тому

    Subscribed :) ! best tutorial seen so far!

  • @muhammadsarimmehdi
    @muhammadsarimmehdi 3 роки тому

    Java gives a warning when I try to use Iterator in the interface. Is there any workaround to it?

  • @pushkarajpatil4787
    @pushkarajpatil4787 8 років тому

    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++

  • @LuizaDreamsDeutsch
    @LuizaDreamsDeutsch 2 роки тому

    Thank you for the video! It was very understandable and has helped me a lot 😃

  • @antoniszewczyk5943
    @antoniszewczyk5943 9 років тому

    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 iterator = birds.iterator()
    and then I am able to use functions like hasNext() or any other?

    • @fabioesposito6823
      @fabioesposito6823 8 років тому

      It's usefull here to encapsulate the way you get the iterator. For example, it differs with the map, you have to call values() first.

  • @davyjones9937
    @davyjones9937 4 роки тому

    THX, Great explanation, Do you have by any chance the uml diagram of this implementation?

    • @derekbanas
      @derekbanas  4 роки тому +1

      Thank you :) Sorry, but I don't

  • @derekbanas
    @derekbanas  12 років тому

    You're very welcome :)

  • @ninonazghaidze7687
    @ninonazghaidze7687 5 років тому

    Very simple and smart ^_^ thanks!

  • @derekbanas
    @derekbanas  12 років тому

    Thank you :)

  • @qaipak1
    @qaipak1 9 років тому +1

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

    • @derekbanas
      @derekbanas  9 років тому

      +K Badsha Sorry if it was confusing. We implement the interface SongIterator, but we can't instantiate it

    • @qaipak1
      @qaipak1 9 років тому

      I understand it now :)

  • @wenlinf1023
    @wenlinf1023 2 роки тому

    very helpful! thank you!

  • @sasagajic
    @sasagajic 11 років тому

    But what should be done when classes are compiled and can't be modified? Bunch of adapter patterns? By studying Software Engineering i become allergic to changing tested code :)

  • @wjrasmussen666
    @wjrasmussen666 10 років тому

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

    • @aysikl
      @aysikl 10 років тому

      Im a nub,
      But!-- have you tried @SuppressWarnings("Iterable")?
      I think "Serializable" was one.. try case sensitive and grammatic siblings n cousins.. :)

    • @StingJia
      @StingJia 9 років тому

      wjrasmussen666
      Change the function in interface SongIterator from :
      public Iterator createIterator();
      To :
      public Iterator createIterator();

  • @bijoythecooldude
    @bijoythecooldude 9 років тому

    Hi Derek,
    Fantastic explanation :), thank you ..

    • @derekbanas
      @derekbanas  9 років тому

      Bijoy Baral Thank you :) Your welcome

  • @suchismitagoswami5609
    @suchismitagoswami5609 2 роки тому

    Absolute, an awesome and clean explanation. However, I think we can rename the interface to SongIterable (containing the createIterator method) to make it sounds like the collection (e.g. SongOfThe70s or SongOfThe80s) is iterable

  • @pratik7775
    @pratik7775 9 років тому

    that was awesome code man thanks it helped me

    • @derekbanas
      @derekbanas  9 років тому

      PRATIK RAJPUT Thank you :) I'm glad it helped

  • @august0490
    @august0490 11 років тому +4

    Good. Just a suggestion: you should show diagrams at the begining of the each pattern explanation.
    Thank you.

  • @AntoniaIvanovaStorm
    @AntoniaIvanovaStorm 11 років тому +16

    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..

    • @derekbanas
      @derekbanas  11 років тому +17

      I agree that I could do many videos on each pattern. I didn't at the time because I was still learning how to better do tutorials.
      Now I have a bigger audience. I listen to what they are struggling with and then I recover those topics as tutorials continue.
      I'm very open to criticism. I love when people tell me they need further help in the comments. That completely controls what I cover in the next videos.
      I also know I move pretty fast. I want to make original videos. That made me decide to move quicker, but to also describe what I was doing and thinking more then I've seen in other tutorials. I constantly try to improve my speed. Thank you for the input :)

  • @thebuzz2010
    @thebuzz2010 9 років тому

    Why Hashtable and not Hashtable ?

    • @DanFletcher90
      @DanFletcher90 9 років тому +3

      +Andrew Daly Java’s generic programming does not apply to the primitive types, such as "int" since generic data structures can only hold objects, while values of primitive type are not objects.
      However Java's wrapper classes such as "Integer" behave the same as ints but they are actually objects, and thus can be used in generic types like Iterators and Hashtables.
      Check out this SO thread: stackoverflow.com/questions/13216314/hashmap-does-not-work-with-int-char

    • @thebuzz2010
      @thebuzz2010 9 років тому +1

      thank you, interesting.

  • @saimraza8342
    @saimraza8342 4 роки тому

    Hi Derek. I am unable to open the code links. It hangs indefinitely. Could you please help?

    • @saimraza8342
      @saimraza8342 4 роки тому

      Works by explicitly prefixing in the redirected URL - www.newthinktank.com/2012/10/iterator-design-pattern-tutorial/

  • @kgnunwei
    @kgnunwei 10 років тому

    Great explanation! Thanks a lot.

  • @jlromano92
    @jlromano92 11 років тому +1

    nice! congrats from Brazil

  • @valentincontilde
    @valentincontilde 3 роки тому +1

    Thank you so much

    • @derekbanas
      @derekbanas  3 роки тому +1

      Thank you :) I'm happy you like them

  • @gaokaicen
    @gaokaicen 11 років тому

    you are a great guy

  • @pr0master
    @pr0master 12 років тому

    Great!! Thanks for your time and effort!

  • @arunsasidharannambiar
    @arunsasidharannambiar 11 років тому

    Hey Derek, could you do a video on Circular Buffer?

  • @sehajpreetsingh4177
    @sehajpreetsingh4177 5 років тому +1

    Here is an implementation that does it using Java Iterator and by defining your own Iterator Interface.
    CODE:
    import java.util.*;
    interface SongIterator
    {
    boolean hasNext();
    SongInfo next();
    }
    class ConcreteSongIterator implements SongIterator
    {
    List l;
    int counter;
    ConcreteSongIterator(List l)
    {
    this.l=l;
    counter=0;
    }
    public boolean hasNext() {
    return (counter

  • @Gabriel_Manchim
    @Gabriel_Manchim 10 років тому

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

  • @rupalipawaskar3725
    @rupalipawaskar3725 9 років тому

    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.

    • @derekbanas
      @derekbanas  9 років тому

      Rupali Pawaskar Thank you :) The head first book is good for a simple explanation and then the book Design Patterns: Elements of Reusable Object-Oriented Software covers everything in detail.

  • @ashwinkumar3531
    @ashwinkumar3531 6 років тому

    thank you , well explained

  • @davix4210
    @davix4210 9 років тому

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

  • @fabioesposito6823
    @fabioesposito6823 8 років тому

    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 :)

  • @f4il6o6
    @f4il6o6 4 роки тому

    Pattern starts at 15:00

  • @derekbanas
    @derekbanas  12 років тому

    Congrats :)

  • @MohsenMoeini
    @MohsenMoeini 10 років тому

    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 .

    • @derekbanas
      @derekbanas  10 років тому +1

      Mohsen Moeini Thank you :) I have all of the code here www.newthinktank.com/2012/10/iterator-design-pattern-tutorial/

  • @MusicalSawMen
    @MusicalSawMen 12 років тому

    Podium !
    Your the John Lennon of Tutorial !

  • @sa7ary.
    @sa7ary. 9 років тому +1

    thank you

    • @derekbanas
      @derekbanas  9 років тому

      +Sahar Mu. Thank you :) You're very welcome

  • @davix4210
    @davix4210 9 років тому

    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 !

    • @derekbanas
      @derekbanas  9 років тому

      +davix Your welcome :) That line of code is fine. Try comparing your code to mine www.newthinktank.com/2012/10/iterator-design-pattern-tutorial/

    • @davix4210
      @davix4210 9 років тому

      +Derek Banas
      Sorry to trouble you ! In fact, I've compared the code but still could not find the problems then I asked you. So far three Design Patterns' code: Iterator, Abstract Factory and Interpreter can not run successfully in my environment. Is it possible the difference of the JDK or something else ?
      Thanks a lot !

  • @Eskew251
    @Eskew251 12 років тому

    you know you are the best right ? how about tuts about frameworks ,building java application..

  • @vasupolchatmethakul5242
    @vasupolchatmethakul5242 9 років тому

    should i still buy the book even after your tutorial?

    • @derekbanas
      @derekbanas  9 років тому

      Vasupol Chatmethakul The GOF book is a good investment because it covers patterns in more detail then I do here.

  • @chandanasrilaluom
    @chandanasrilaluom 12 років тому

    is there source code?

  • @reizhustenistdoof
    @reizhustenistdoof 7 років тому +1

    I don't like this video.
    The example ads way too much overhead that distracts from the iterator pattern and in the end you don't even really implement it .

  • @chandanasrilaluom
    @chandanasrilaluom 12 років тому

    great ...thanks..

  • @DevDamian
    @DevDamian 12 років тому

    great tuts :-)

  • @gytautebarzdziute7358
    @gytautebarzdziute7358 3 роки тому

    Can you help me to implement in songsofthe70s.java Iterator class something like that?
    @Override
    public Iterator CreateIterator() {
    Iterator it = new Iterator() {
    private int currentIndex = 0;
    @Override
    public boolean hasNext() {
    return currentIndex < currentSize && bestSongs[currentIndex] != null;
    }
    @Override
    public Type next() {
    return bestSongs[currentIndex++];
    }
    @Override
    public void remove() {
    throw new UnsupportedOperationException();
    }
    };
    return it;
    }
    }

  • @Weissiiii
    @Weissiiii 10 років тому

    Thanks!!!!!

    • @derekbanas
      @derekbanas  10 років тому

      You're very welcome :)

    • @Weissiiii
      @Weissiiii 10 років тому

      Derek Banas You helped me to understand what my prof wasn't able to explain :)

    • @derekbanas
      @derekbanas  10 років тому

      Weissiiii Thank you :) I'm happy that I could help.

  • @JonathonSins
    @JonathonSins 6 років тому

    I really just want to hear you say "Drugs are bad mmmmkay?"

  • @wase39
    @wase39 11 років тому

    yea good point .
    any way thank Derek your doing a great job (Y)

  • @rachelr22
    @rachelr22 4 роки тому

    I'm going crazy because the 70's songs won't output

    • @rachelr22
      @rachelr22 4 роки тому

      lol nevemind just did a dumb mistake that I couldn't find for 30 minutes straight

  • @TRana9
    @TRana9 9 років тому +4

    I LOVE YOU

  • @vinays2496
    @vinays2496 6 років тому +1

    I just watched 23 minutes of video to see how to use existing java iterator. I was hoping to see how exactly an iterator design pattern is realized .

  • @tianyilong2007
    @tianyilong2007 6 років тому

    finally, english

  • @VarjoFilosofi
    @VarjoFilosofi 12 років тому

    Haha, it was painful to watch so much copy paste code what you did before doing it with Iterator.

  • @tekal85
    @tekal85 8 років тому

    100#

  • @Deus_Ignis
    @Deus_Ignis 3 роки тому

    at 6:14 bestSongs[arrayValue] = song , song is undefined ?

  • @derekbanas
    @derekbanas  12 років тому

    You're very welcome :)