Iterator Mode
2016-12-19 14:01:13 3 举报
用同一个迭代器,迭代两个不同的组合。
作者其他创作
大纲/内容
Dependency
Aggregation
LunchMenu
-menuItems:ArraryList
+LunchMenu()+CreateIterator():IIterator
DinerMenuIterator
-items:MenuItem[]-index:int = 0
+DinerMenuIterator(MenuItem[] items)+HasNext():bool+Next():object
IMenu
+CreateIterator():IIterator
DinerMenu
-MAX_ITEM_NUM:int = 6-menuItems:MenuItem[]
+DinerMenu()+CreateIterator():IIterator
Realization
public DinerMenu(){ //create menuItems}public IIterator CreateIterator(){ return new DinerMenuIterator(this.menuItems);}
LunchMenuIterator
-items:ArraryList
LunchMenuIterator(ArraryList items)+HasNext():bool+Next():object
Waitress
-lunchMenu:IMenu-dinerMenu:IMenu
public DinerMenuIterator(MenuItem[] items){ this.items = items;}public bool HasNext(){ if(this.index = this.items.length || items[this.index] == null) { return false; }else{ return true; }}public object Next(){ MenuItem menuItem = this.items[this.index]; this.index++; return menuItem;}
IIterator
+HasNext():bool+Next():object
MenuItem
-name:string-desc:string-vagetarian:bool-price:double
+MenuItem(...)
0 条评论
下一页