1 Preface
In object-oriented systems, the design pattern for the iterative behavior of abstract sets is called the iterator.
2. Details
2.1 Brief Introduction
The iterator provides a method to access elements in an aggregate object (SET) sequentially without exposing the underlying representation and details of the structure. Elements in a convenient set can only be transferred from the set itself to the iterator object. The iterator defines an interface used to access the collection element and record the current element. Different iterators can execute different traversal policies.
Provides a method to access each element in an aggregate object sequentially without exposing the internal representation of the object.
2.2 category
External iterator: allows the client to directly operate the iteration process. Therefore, the client must know the external iterator before using it.
Internal iterator: A collection object (the target object to be iterated) maintains and operates an external iterator within it. A typical set object of the internal iterator is provided to define an interface for the client, or access an element at a time from the underlying set, or send messages to each element.
2.3 when to use
(1) access the content of the composite object without exposing its internal representation;
(2) The composite object needs to be traversed in multiple ways;
(3) A unified interface is required to traverse various types of composite objects.
3 conclusion
The above is all content and I hope it will help you.