The Iterator Design Pattern

The Iterator Design PatternShort Description
Iterators as a design pattern are much more apparent as a pattern in languages …… The Iterator design pattern has three parts: the data, the iterator, …

Website: www.theperlreview.com | Filesize: 410kb

Content
The Iterator Design Pattern
brian d foy, comdog@panix.com
Abstract
The Iterator pattern separates the details of traversing a collection so that they can vary independently.
Perl provides some of these parts already, although in some cases I need to provide my own
implementations of them.
1 Introduction
Iterators as a design pattern are much more apparent as a pattern in languages that do not have aggregates
as first class objects. Perl has lists, along with the variable types arrays and hashes, and it is trivial to go
through any of these with built-in Perl structures like foreach, each, map, and so on. The file input operator,
<>, iterates through the lines of the file. The readdir() and glob() functions iterate through filenames. In
scalar context, the match operator with the global flag, m//g, iterates through matches.
In Perl I do not have to write classes to traverse an array, but I may need to write code to go through my
own complex data structures because Perl’s built-in control structures, like foreach(), map(), and grep(), do
not define an interface that objects can use to control the iteration. They take a list, and I have to…

Get the file Download here

AddThis Social Bookmark Button
Related Books:
  • LINQ in Action Chapter 3
  • Generating design pattern detectors from pattern specifications …
  • The Visitor design pattern
  • Douglas C. Schmidt Case Studies Using Patterns Case Study …
  • Model-View-Controller A Design Pattern for Software
  • Automatic resource management as a C++ design pattern
  • The Perl Review
  • POD a composition environment for pattern-oriented design …

  • Related Searches: , , , ,



    Comments

    Leave a Reply




    Search engine terms: C iterator pattern,