课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Using the Iterator pattern
- [Instructor] Let's take a look at the class diagram for the iterator pattern and then we'll see how to implement it for the menus. In our example, the aggregate object is a menu which uses an array list or an array to store the menu items. We have an aggregate interface and a concrete aggregate class that implements that interface, providing a method, create iterator, that creates and returns an iterator object. The client stores that iterator and then, when it needs to iterate over the items in the aggregate object, it can use the methods defined by the iterator interface to do so. The hasNext method figures out if there are more items to iterate over and the next method just returns the next item. Here's how we'll design our menus example to use the iterator pattern. Our aggregate object will be the menu. We'll add a menu interface that defines one method, create iterator, and both the pancake house menu and the…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
-
(已锁定)
Encapsulating iteration1 分钟 44 秒
-
(已锁定)
Understanding the Iterator pattern2 分钟 28 秒
-
(已锁定)
Using the Iterator pattern3 分钟 36 秒
-
(已锁定)
Using built-in iterators1 分钟 19 秒
-
(已锁定)
The single responsibility principle1 分钟 20 秒
-
(已锁定)
The iterator pattern as language feature1 分钟 30 秒
-
(已锁定)
Challenge: The Iterator pattern57 秒
-
(已锁定)
Solution: The Iterator pattern36 秒
-
(已锁定)
-
-