1 00:00:00,770 --> 00:00:07,460 The 18 pattern is best used whenever there's a need to traverse a data structure and access its elements. 2 00:00:08,530 --> 00:00:12,790 You may wonder why you would need this battery instead of a loop to traverse a collection. 3 00:00:13,860 --> 00:00:20,550 Well, the good thing about this battle is that it does not expose the underlying structure of the container 4 00:00:20,550 --> 00:00:21,750 that is being traversed. 5 00:00:22,940 --> 00:00:27,740 The iterators decouples the data from the algorithm used for traversing a container. 6 00:00:28,710 --> 00:00:34,940 A very good example of an iterator is the Java dot dot iterator interface from the Java API. 7 00:00:36,450 --> 00:00:42,600 Looking at the UML diagram for this pattern, you can see that we have two abstractions for the container 8 00:00:42,600 --> 00:00:48,720 that will be traversed and for the iterator, the employee director class will implement the container 9 00:00:49,020 --> 00:00:53,460 and it will be based on the list containing the names of the employees of a company. 10 00:00:54,840 --> 00:01:00,480 When they enter, their class will implement the iterator and it will contain the algorithm for its 11 00:01:00,480 --> 00:01:02,250 overseeing the employees container. 12 00:01:03,180 --> 00:01:05,820 Let's see how this can be implemented in the code.