课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
Encapsulating iteration
- We have many ways to store collections of objects in data structures. For example, most modern programming languages provide arrays. If you're using Java, you could store menu items for a menu in an array like this. Most languages provide additional structures for storing collections of objects like lists, dictionaries and sets. For example, Java provides an ArrayList, which is a lot like an array, but has some list like capabilities too. Here we're storing our menu items in an ArrayList. Simple enough, but what if we need to write code that operates over several of these collection types? Let's say you want to write a print method to print any menu. To print a menu, we need to iterate over the collection that's storing the menu items. If you're using an array to store your menu items, you'll write code like this. Now if you decide to change the representation of menus from an array to an ArrayList, you end up…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
-
-
-
(已锁定)
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 秒
-
(已锁定)
-
-