• Home
  • About Jon Dowdle
  • Lifestream
KEEP IN TOUCH

Posts tagged iterator

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

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