• Home
  • About Jon Dowdle
  • Lifestream
  • Code from TDD Demystified through Kat...
    Passing

    A big thanks to everyone that came out for today's CFMeetup. The code is located here and the presentation is located here. While practicing for this presentation, I noticed [...]

    Read more
KEEP IN TOUCH

Design Patterns in Coldfusion (Iterator Pattern)

Jul08
2008
Written by Jon Dowdle

This is the second article on design patterns in Coldfusion. Part one can be viewed here.

Quick Description
The iterator provides a single way to loop over a collection of elements without having to worry which type of collection (list, struct, array, query) it is. The interface for an iterator is quite simple with the main methods being hasNext() and next(). hasNext() returns true or false depending on if there are additional elements, while next() returns the next elements.

Speaking of collections, there is a collection class included with the source files. Using a class to contain the collection is preferable because it abstracts the data storage method for groups of objects, which lets us use the iterator class seamlessly. I find being ignorant of the underlying data type gives much more flexibility. I plan on going to more detail with the AbstractCollection and the implementation more in a future post.

Most of the code is taken from Brendan O'Hara's article, with the largest exception being the addAll() method in my PersonCollection.cfc. So again, many thanks to him for his wonderful post on CFDJ.

Included Examples:

  • AbstractIterator.cfc
    • Abstract class (with CF8 this could be replaced with <cfinterface>)
  • ArrayIterator.cfc
    • Class to handle iterating over Arrays
  • PersonCollection.cfc
    • Maintains a collection of Persons
  • Person.cfc
    • Basic class
  • Test.cfm
    • Instantiates and displays output forĀ all these CFCs

Links:
Iterator Source Files

Brendan O'Hara's Iterator Article

Posted in Code, Programming, Web Design - Tagged adobe, coldfusion, design pattern, iterator
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Design Patterns in Coldfusion (Decorator Pattern)
» Summer Reading List

2 Comments

  1. Ilya Fedotov's Gravatar Ilya Fedotov
    July 18, 2008 at 10:13 pm | Permalink

    Hello, can you please share your implementation. I think you intended to but the link doesn’t seem to contain the files. Thanks.

  2. Jon Dowdle's Gravatar Jon Dowdle
    July 18, 2008 at 10:25 pm | Permalink

    @Ilya Thanks for pointing that out. I’ve fixed the link above and here it is again: Iterator Source Files

Recent Posts

  • Code from TDD Demystified through Katas
  • Awesome Web Development Links Found This Week
  • Taggable Demo Video (now with more code)
  • Taggable Demo Video
  • New jQuery Plugin: Taggable

Categories

  • Code
    • MySQL
    • Programming
    • Web Design
  • coldfusion
  • Life
    • Events
  • Reviews
  • Uncategorized
  • Work

Tags

adobe barcamp barcamporlando coldfusion ComplexByteArrayException concat conferences decorator design pattern Events firebug Form fowa html IE ignite infection control iterator javascript job jQuery movies MySql orlando Photos pirate booty pirates plugins poll project python railo software development sql stackoverflow stax.net style taggable tags talk like a pirate tips & tricks tools twitter washington dc Web Design

RSS Syndication

  • All posts
  • All comments

EvoLve theme by Theme4Press  •  Powered by WordPress jDowdle.com