Iterator Pattern
Iterator : accesses the elements of an object sequentially without exposing its underlying representation.
- 특정 집합체의 요소들을 순서대로 접근해서 처리
for문의 index 기능을 추상화- 왜
for나while대신Iterator를 만들어 사용하는걸까?
Iterator 패턴의 요소
- Iterator interface : 반복자, index를 가지고 있다.
- ConcreteIterator (implements Iterator)
- Aggregate interface : 집합체, Iterator를 생성하는 역할
- ConcreteAggregate (implements Aggregate)
UML

Why we shold use Iterator?
Iterator를 사용하면ConcreteAggregate구현에 의존하지 않고 loop를 사용할 수 있음.Aggregate,IteratorPair를 사용함으로써 iteration의 추상화가 가능.
확장
- 뒤에서 시작해서 역방향으로 진행하도록 구현.
- 양 방향을 진행하도록 next(), previous()를 구현.
- 특정 index로 jump하도록 구현.
관련 패턴
Visitor:Iterator+ 처리 로직 (돌아다니면서 하나씩 직접 처리)Composite: 재귀 구조패턴이므로Iterator적용이 어려움.Factory Method:Iterator인스턴스를Factory Method로 구현