O'Reilly logo

Design Patterns in Ruby by Russ Olsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. Reaching into a Collection with the Iterator

In Chapter 6, we looked at composites—objects that appear to be simple components but are actually made up of a collection of subcomponents. Of course, an object does not have to be a composite to know about collections of other objects. An Employee object might know about several dependents, or phone numbers, or, in the case of a well-paid executive, the addresses of many palatial estates. In this kind of situation, it would be helpful if we could sequence through all of the sub-objects without needing to know any of the details of how the aggregate object is storing them.

In this chapter, we will explore the Iterator pattern, a technique that allows an aggregate object to provide the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required