Defined:
The iterator pattern provides a way to sequentially access individual elements in an aggregated object without exposing the object's internal representation.
Because of the extensive use of iterator patterns, now high-level languages such as C#,java have already encapsulated this pattern in language. For example, in C #, foreach in.
So this is not a detailed introduction to the iterator pattern here, the following is a brief description of some of the basic knowledge that is seen in the book:
Ieumerator supports simple iterative interfaces to non-generic collections.
Public Interface Ieumerator { objectget;} BOOL MoveNext (); void Reset (); }
IEnumerable exposes an enumerator that supports simple iterations on a non-generic collection.
Public Interface IEnumerable { ieumerator GetEnumerator (); }
Simple example:
ilist<string> strlist =Newlist<string>(); Strlist.add ("a"); Strlist.add ("C"); Strlist. ADD ("D"); foreach(stringIteminchstrlist) {Console.WriteLine ("{0}", item); }
Design mode (---) iterator mode