SOFTWARE ENGINEERING

SOFTWARE DESIGN

DESIGN PATTERNS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Use the Iterator pattern when your collection has a complex data structure under the hood, but you want to hide its complexity from clients (either for convenience or security reasons).
A
True
B
False
C
Either A or B
D
None of the above
Explanation: 

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.

There is 1 question to complete.