Purpose
Iterator pattern is very commonly used design pattern in Java and .Net programming environment. This pattern is used to get a way to access the elements of a collection object in sequential manner without any need to know its underlying representation.
Play with an Example
I have an old IPOD mini divice is there, which bit old but still i love that. It have a collection of my favorate melodys. Also the device is very simple It just have only a limitted set of buttons are there. Volume UP/DOWN, Next Track, Previous Track, Play Pause.
The iterator design pattern is same as the Next/Prevous track buttons in my IPOD. Those button will switch the songs in a sequential manner.
Lets Implement my IPOD Minis Next functionality by using Iterator design Pattern
Advanced Points
- The abstract syntax tree of Interpreter is a Composite (therefore Iterator and Visitor are also applicable).
- Iterator can traverse a Composite. Visitor can apply an operation over a Composite.
- Polymorphic Iterators rely on Factory Methods to instantiate the appropriate Iterator subclass.
- Memento is often used in conjunction with Iterator. An Iterator can use a Memento to capture the state of an iteration. The Iterator stores the Memento internally.
No comments:
Post a Comment