일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Gradle
- spark
- Hbase
- 제주
- design pattern
- DDD
- hdfs
- elasticsearch
- Linux
- Spring
- Spring Boot
- nginx
- scala
- hadoop
- Java
- hibernate
- Storm
- Clean Code
- Spring XD
- 인텔리J
- SBT
- 도메인주도설계
- Spring Batch
- Angular2
- 엘라스틱서치
- intellij
- 스프링 배치
- elastic search
- apache storm
- docker
- Today
- Total
욱'S 노트
Iterator - 순환 구조 만들기 본문
Heavy한 Job이 수행되는 클래스들을 미리 만들어 놓고 공유하고 싶을때
Class Diagram
public interface Aggregate {
}
public interface Iterator {
public Object next();
public boolean hasNext();
}
public class ConcreteAggregate implements Aggregate {
private Object[] items;
public Iterator iterator() {
return new ConcreteIterator(this);
}
public Object getItem(int index) {
if ( index < items.length - 1)
return items[index];
else
return null;
}
public int getLength() {
return items.length;
}
}
public class ConcreteIterator implements Iterator {
private ConcreteAggregate aggregate;
private int index;
public ConcreteIterator(ConcreteAggregate aggregate) {
this.aggregate = aggregate;
this.index = 0;
}
@Override
public Object next() {
Object item = aggregate.getItem(index);
if ( item != null ) {
index++;
}
return item;
}
@Override
public boolean hasNext() {
if ( index < aggregate.getLength()) {
return true;
} else {
return false;
}
}
}
Caution
특별한 주의사항은 없다.
'Methdology > Design Pattern' 카테고리의 다른 글
Strategy - 알고리즘 교체 하기 (0) | 2012.04.25 |
---|---|
Template Method - 구체적인 수행을 하위로 위임하기 (0) | 2012.04.24 |
Flyweight - 만들어 놓고 공유하기 (0) | 2012.04.18 |
Proxy - 필요할때 만들기 (0) | 2012.04.18 |
Composite - 계층구조 만들기 (0) | 2012.04.16 |