SOFTWARE DESIGN
DESIGN PATTERNS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
True
|
|
False
|
|
Either A or B
|
|
None of the above
|
Detailed explanation-1: -Real world example of iterator pattern All Java collections provide some internal implementations of Iterator interface which is used to iterate over collection elements. In media players, we have a list of songs listed and we can play the song by traversing to the songs list and select desired song.
Detailed explanation-2: -Answer: In order to use the iterator to traverse through the collection, first, you have to get the iterator using the iterator() method of the specified collection. Then you can use the hasNext() and next() methods of the iterator to get the element.
Detailed explanation-3: -The elements of an aggregate object should be accessed and traversed without exposing its representation (data structures). New traversal operations should be defined for an aggregate object without changing its interface.