• 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 (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 adobe, coldfusion, decorator, design pattern
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Movies I want to see
» Design Patterns in Coldfusion (Iterator Pattern)

1 Comment

  1. Jason Seminara's Gravatar Jason Seminara
    September 30, 2008 at 10:30 pm | Permalink

    Thanks for posting these code examples. I’ve been reading recently about the Decorator Pattern and CF, but I’ve been confused about who exactly is inheriting from WHOM. Your examples cleared up some confusion.
    Thanks.

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