HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
남득윤 학습 저장소
/
객체 지향 프로그래밍
객체 지향 프로그래밍
/
디자인 패턴
디자인 패턴
/
Iterator Pattern
Iterator Pattern
Iterator Pattern

Iterator Pattern

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

notion image
  • Iterator - Iterator 인터페이스
  • ConcreteIterator - 구체 반복자 클래스
  • IterableCollection - Iterator를 생성하는 인터페이스 제공
  • ConcreteICollection - 구체 콜렉션
 
 

Applicablity

  • 클라이언트에게 복잡한 자료 구조의 내부 구현을 숨기고 싶을때
  • 순회 코드의 중복을 줄이고 싶을때

Examples

Here are some examples from core Java libraries:
  • All implementations of java.util.Iterator (also java.util.Scanner).
  • All implementations of java.util.Enumeration