From the course: Programming Foundations: Design Patterns
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
The iterator pattern as language feature
From the course: Programming Foundations: Design Patterns
The iterator pattern as language feature
- [Instructor] The iterator pattern is one of those patterns that is so useful it's become built-in to languages as language features. Languages provide built-in iterators as we saw with Java collections and they use iterators in language statements too. These statements hide the iterator pattern and it's iterators behind the scenes and make it easy to iterate through collections of values. Java, Python and JavaScript all have statements that use the iterator pattern behind the scenes. Java's enhanced for statement is designed for iteration through collections and arrays. So this code will work whether animals is an ArrayList of animal objects or an array of animal objects. Python's for/in statement can be used with any iterable aggregate object such as string, list and tuple and JavaScript's for/of statement can be used with strings, arrays, maps and sets. All of which are iterable objects meaning there are iterators…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Encapsulating iteration1m 44s
-
(Locked)
Understanding the Iterator pattern2m 28s
-
(Locked)
Using the Iterator pattern3m 36s
-
(Locked)
Using built-in iterators1m 19s
-
(Locked)
The single responsibility principle1m 20s
-
(Locked)
The iterator pattern as language feature1m 30s
-
(Locked)
Challenge: The Iterator pattern57s
-
(Locked)
Solution: The Iterator pattern36s
-
(Locked)
-
-
-