• Home
  • About Jon Dowdle
  • Lifestream
KEEP IN TOUCH

Posts tagged adobe

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 coldfusion, design pattern, iterator

Design Patterns in Coldfusion (Decorator Pattern)

Jul03
2008
Written by Jon Dowdle

Recently, I have become interested obsessed with design patterns.  What caused the spark of excitement was that I was working on an algorithm similar to one of the patterns (I can't remember which) when I read Head First Design Patterns and realized it had already been created for me! By the way, I'd recommend Head First, it's a great learning series.

Also, I use the term "class" for "component" and "method" for "function". So without further ado,  my first article on implementing design patterns in Coldfusion.

Decorator Pattern

A decorator more or less wraps a base class and well...decorates it. This can be useful when you have a scenario that would need a lot of classes to cover all of the possible combinations of objects.

My Implementation

I followed the example by Hal Helms as far as the class organization is concerned.  Some of the decorators are me being funny (piglatin and mirror), but I can see some value in the TableDecorator, JsonDecorator and XmlDecorator.

Let me explain each file a bit more.

  • Test.cfm
    • Instantiates the components and outputs results
  • Person.cfc
    • Base class (whose methods will be overridden by the decorators)
  • PersonDecorator.cfc
    • Base decorator class (all decorators for Person will inherit from this class)
  • PersonJsonDecorator.cfc
    • Creates a JSON representation of a Person.
  • PersonXmlDecorator.cfc
    • Creates a XML representation of a Person by wrapping the elements with nodes that represent each element
  • PersonTableDecorator.cfc
    • Creates a table representation of a Person by wrapping elements with <td>'s and the entire Person with <tr>

Links

Source Files

Wikipedia's Page on Decorators

Hal Helm's Decorator Article

Posted in Code, Programming, Web Design - Tagged coldfusion, decorator, 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