Intent
Iterator is a behavioral design pattern that lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.).
이터레이터 패턴의 핵심 아이디어는 콜렉션을 순회하는 행위를
iterator
라는 객체에 분리하는 것입니다.Implementation

Iterator
- Iterator 인터페이스
ConcreteIterator
- 구체 반복자 클래스
IterableCollection
- Iterator를 생성하는 인터페이스 제공
ConcreteICollection
- 구체 콜렉션
Applicablity
- 클라이언트에게 복잡한 자료 구조의 내부 구현을 숨기고 싶을때
- 순회 코드의 중복을 줄이고 싶을때
Examples
Here are some examples from core Java libraries:
- All implementations of
java.util.Iterator
(alsojava.util.Scanner
).
- All implementations of
java.util.Enumeration