差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン | |||
| study:java:design_pattern:iterator [2008/09/13 03:53] – banana | study:java:design_pattern:iterator [2008/09/13 04:03] (現在) – banana | ||
|---|---|---|---|
| 行 21: | 行 21: | ||
| 이제 클래스 다이어그램을 살펴보도록 할까요? | 이제 클래스 다이어그램을 살펴보도록 할까요? | ||
| + | |||
| ===== Class Diagram ===== | ===== Class Diagram ===== | ||
| {{: | {{: | ||
| + | |||
| + | %%ConcreteIterator%% 구상클래스의 예로 배열에 대해 Iterator 인터페이스를 구현해 보겠습니다. | ||
| + | |||
| + | ===== Implement an Iterator interface ===== | ||
| + | <code java> | ||
| + | import java.util.Iterator; | ||
| + | |||
| + | public class DinnerMenuIterator implements Iterator{ | ||
| + | MenuItem[] list; | ||
| + | int position = 0; | ||
| + | |||
| + | public DinnerMenuIterator(MenuItem[] list){ | ||
| + | | ||
| + | } | ||
| + | |||
| + | public Object next(){ | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | |||
| + | public boolean hasNext(){ | ||
| + | | ||
| + | return false; | ||
| + | } else { | ||
| + | return true; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | public void remove(){ | ||
| + | | ||
| + | throw new IllegalStateException(" | ||
| + | } | ||
| + | | ||
| + | for(int i = position-1; i < (list.length-1); | ||
| + | | ||
| + | } | ||
| + | list[list.length-1] = null; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||