# Iterator Pattern

> A design pattern that lets callers traverse a collection without seeing how it is stored.

Record: `architecture:iterator-pattern`
Kind: pattern
Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)
Severity: contextual
Scope: behavior, traversal, collection
Canonical: https://banes-lab.com/ontology#architecture-iterator-pattern

Listed in [Architecture principles](https://banes-lab.com/api/records/architecture.md), after [Chain of Responsibility Pattern](https://banes-lab.com/records/architecture/chain-of-responsibility-pattern.md) and before [Visitor Pattern](https://banes-lab.com/records/architecture/visitor-pattern.md).

## Repair

- Refactored by: Introduce Iterator
- Detected by: index/pointer traversal of another type's internals
- Violated by: callers walking a structure's internal fields directly
- Measured by: internal-structure access count
- Enforced by: [design review](https://banes-lab.com/records/architecture/design-review.md)

## Requires

- [Uniform Traversal Interface](https://banes-lab.com/records/lexicon/uniform-traversal-interface.md)

## Reinforces

- [Encapsulation](https://banes-lab.com/records/architecture/encapsulation.md)
- [Single Responsibility Principle (SRP)](https://banes-lab.com/records/architecture/single-responsibility.md)

## Enables

- [Structure-Agnostic Iteration](https://banes-lab.com/records/lexicon/structure-agnostic-iteration.md)
- [Lazy Traversal](https://banes-lab.com/records/lexicon/lazy-traversal.md)

## Conflicts with

- [Exposed Internal Representation](https://banes-lab.com/records/lexicon/exposed-internal-representation.md)

## In tension with

- [Simplicity](https://banes-lab.com/records/lexicon/simplicity.md)

## Tensions

- [Iterator Pattern / Simplicity](https://banes-lab.com/records/tension/iterator-pattern-simplicity.md)

## Severity

- [contextual](https://banes-lab.com/records/vocabulary/severity-contextual.md)

## Category

- [Behavioral Patterns](https://banes-lab.com/records/architecture-category/behavioral-patterns.md)

## Linked from

- [Core Modular Design](https://banes-lab.com/ontology/principles/architecture-category-core-modular-design.md)
- [Behavioral Patterns](https://banes-lab.com/ontology/lexicon/lexicon-category-behavioral-patterns.md)
- [Quality Attributes](https://banes-lab.com/ontology/lexicon/lexicon-category-quality-attributes.md)
- [Severity levels](https://banes-lab.com/ontology/schema/the-vocabulary-severity.md)
- [The resolutions](https://banes-lab.com/ontology/schema/the-resolutions.md)
