Iterator pattern

An Iterator is a design pattern used in software engineering. iterators allows access to the elements of an aggregate or collection data structure. Sometimes th

An Iterator is a design pattern used in software engineering. iterators allows access to the elements of an aggregate or collection data structure. Sometimes this pattern is also called cursor. Using the iterator, the elements of the data structure can be accessed sequentially, without exposing the implementation. Usually, iterators have methods to ask whether there is another item, and to get the next item. Depending on the implementation, they might also have methods for removing the current element or for finding the next element that meets certain criteria. In some implementations, iterators can only traverse data structures in one direction, while others allow traversal in both directions.

Iterators can be implemented in different ways:

  • In the case of an external iterator, the client controls iteration, with an internal iterator, the iterator controls the iteration. External iterators have been called active, internal iterators have been called passive.
  • In some cases, the way the data structure is traversed is dictated by the data structure, in other cases, it is the iterator that controls the traversal
  • Iterators must be robust against changes of the data structure during iteration. Usually, iterators need to be registered with the data structure.
  • In some implementations, iterators can take advantage of polymorphism.
  • Combining the iterator with the pattern of null object creates an empty (or null) iterator

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.