Html/Javascript widget

Saturday, 17 September 2022

Iterator

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?
  1. The elements of an aggregate object should be accessed and traversed without exposing its representation.
  2. 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.

Different iterators can be used to access and traverse an aggregate in different ways.

No comments:

Post a Comment