In this video, explore the iterator pattern to learn how to encapsulate iteration to avoid changing the code.
- [Instructor] As we've seen, we've got two menus … with two different implementations. … One uses an Array, and the other uses an ArrayList. … That means that the class responsible … for printing the menus, the cafe, … needs to use two different methods … of entering through the menu items. … So the two menus are exposing the details … of how they're implemented to the cafe, … which means that the cafe is dependent … on those implementations. … If someone decides to change the implementation of a menu, … or say, add another type of menu, … that will require code changes to the cafe. … We can reduce the dependency between the cafe … and the menu implementations by using the iterator pattern. … Here's the definition for iterator pattern. … The iterator pattern provides a way … to access the elements of an aggregate object sequentially … without exposing its underlying representation. … that underlying representation. … Let's step through that. … First, what is an aggregate object? … Well that's just a collection of objects, like an Array, …
- What are design patterns?
- Encapsulating code that varies with the Strategy pattern
- The limitations of inheritance
- Using the Adapter pattern
- Implementing the Observer pattern
- Extending behavior with composition and the Decorator pattern
- Encapsulating iteration with the Iterator pattern
- Object creation with the Factory Method pattern
- Using design principles to guide your object-oriented design
Skill Level Intermediate
1. Design Patterns
2. The Strategy Pattern
3. The Adapter Pattern
4. The Observer Pattern
Using the Observer pattern2m 23s
5. The Decorator Pattern
6. The Iterator Pattern
7. The Factory Patterns
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.