The iterator pattern is a behavioural design pattern Chain of responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template method, Visitor in which an iterator is used to traverse a container and access the container's elements. The iterator pattern decouples algorithms from containers.
For example, the hypothetical algorithm SearchForElement can be implemented generally using a specified type of iterator rather than implementing it as a container-specific algorithm. This allows SearchForElement to be used on any container that supports the required type of iterator.
Overview
- What problems can the Iterator design pattern solve?
- The elements of an aggregate object should be accessed and traversed without exposing its representation.
- New traversal operations should be defined for an aggregate object without changing its interface.
- What solution does the Iterator design pattern describe?
- Define a separate (iterator) object that encapsulates accessing and traversing an aggregate object.
- Clients use an iterator to access and traverse an aggregate without knowing its representation.
No comments:
Post a Comment