From the course: Node.js: Design Patterns
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
The Iterator pattern - Node.js Tutorial
From the course: Node.js: Design Patterns
The Iterator pattern
- [Instructor] The iterator is a very common design pattern. It gives us a uniform interface for interacting with lists, collections, arrays, or any type of aggregate object. Iterators are designed to work with collections of data. They give us a clear way to access the first data record, and then they give us a way to iterate through the rest of the rows within our data set. It doesn't matter what type of data you're working with, iterators give us a clear way to iterate through any collection. The Gang of Four defines the intent of the iterator as providing a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Let's take a look at some code. Within the exercise files, under chapter four, lesson six within the start folder, we have a couple of files already set up. We have an inventoryitem.js, which has the class definition for an inventory item. Inventory items just…
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)
Chain of responsibility4m 42s
-
(Locked)
Implementing the storage class6m 22s
-
(Locked)
The Command pattern4m 47s
-
(Locked)
Implementing commands4m 59s
-
(Locked)
Improving the conductor6m 38s
-
(Locked)
The Iterator pattern4m 5s
-
(Locked)
Implementing iterators4m 59s
-
(Locked)
The Observer pattern4m 19s
-
(Locked)
Implementing observers2m 48s
-
(Locked)
The Strategy pattern4m 25s
-
(Locked)
Implementing strategies9m 36s
-
(Locked)
-