
you are here
251
7
章
Adapter
パターンと
Facade
パターン
Enumeration
を
Iterator
に適合させる
<<interface>>
Enumeration
hasMoreElements()
nextElement()
<<interface>>
Iterator
hasNext()
next()
remove()
この
2
つのメソッドは単純です。
Iterator
の
hasNext()
と
next()
に素
直に対応します。
しかし、
Iterator
の
remove()
メソッ
ドはどうでしょうか?
このようなメ
ソッドは
Enumeration
にはありま
せん。
<<interface>>
Enumeration
hasMoreElements()
nextElement()
<<interface>>
Iterator
hasNext()
next()
remove()
実際には背後に
Enumeration
インタ
フェースがあっても、新し
いコードでは
Iterator
イン
タフェースを使うことがで
きます。
EnumerationIterator
hasNext()
next()
remove()
EnumerationIterator
はアダプタです。
Enumeration
イ
ンタフェースを実
装しているクラス
はアダプティです。
古いコードの
Enumeration
を、
新しいコードでは
Iterator
に見え
るようにします。
ターゲットインタフェース
アダプティインタフェース
アダプタを設計する
クラスには、ターゲットインタフェースを実装し ...