この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 次のリビジョン | 前のリビジョン | ||
|
デザインパターン:01_iterator [2019/03/16 21:10] ips 作成 |
デザインパターン:01_iterator [2019/08/24 15:31] (現在) ips |
||
|---|---|---|---|
| ライン 1: | ライン 1: | ||
| - | ====== Iterator:イテレーター ====== | + | ====== 01_Iterator:イテレーター ====== |
| - | {{:デザインパターン:pasted:20190316-210459.png}} | + | <uml> |
| + | title Iterator | ||
| + | |||
| + | interface Aggregate{ | ||
| + | createIterator() | ||
| + | } | ||
| + | |||
| + | interface Iterator{ | ||
| + | +hasNext() | ||
| + | +next() | ||
| + | } | ||
| + | |||
| + | class BookShelf{ | ||
| + | createIterator(this) | ||
| + | } | ||
| + | |||
| + | class BookShelfIterator{ | ||
| + | BookShelf | ||
| + | +hasNext() | ||
| + | +next() | ||
| + | } | ||
| + | |||
| + | Aggregate -> Iterator : Create | ||
| + | Aggregate <|.. BookShelf | ||
| + | Iterator <|.. BookShelfIterator | ||
| + | BookShelf <-o BookShelfIterator | ||
| + | |||
| + | </uml> | ||
| ====== 概要====== | ====== 概要====== | ||
| ライン 7: | ライン 34: | ||
| BookShelfのcreateIteratorメソッドを使ってBookShelfIteratorを作成する。 | BookShelfのcreateIteratorメソッドを使ってBookShelfIteratorを作成する。 | ||
| その際、BookShelf自身を渡すことで、BookShelftとBookShelfIteratorは疎結合となっている。 | その際、BookShelf自身を渡すことで、BookShelftとBookShelfIteratorは疎結合となっている。 | ||
| + | |||
| + | |||
| + | |||