Strategy Design Pattern in Coldfusion

In this blog post I will demonstrate the practical use of strategy design pattern in ColdFusion and discuss other possibilities.

So what is Strategy Design Pattern?
Wikipedia : “In computer programming, the strategy pattern (also known as the policy pattern) is a particular software design pattern, whereby algorithms can be selected at runtime.
Gang of four : “Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

So from the various descriptions it’s clear that this pattern can be used in the situation where there is possibility of having difference/multiple calculation and the application has to choose the right one on the fly.

I am going to use a scenario to build the case on why and how this pattern should be used.

Scenario:

Let’s say there is a web application which has multiple developers working on it, or have multiple teams working on independent section of the application, in such sort of application its fundamental to have core set of components that the developer use and there is also a possibility that they may be used across multiple applications. In such sort of scenario its inherent that core component be stable and least amount of changes should be done on the core components (i.e. cfc’s ) to avoid large scale impacts to other modules/developers.

So let’s say one of the core components that we have is the Customer.cfc it has some properties and also methods which get used by the appropriate section of the web applications

(more…)

1 comment June 28th, 2008

observer design pattern in coldfusion

The observer design pattern is used in application development to observe the state of an object.  The best way to think about it is the publish / subscribe model.  In this pattern you have one object that is being observed (the subject), and a group of objects watching the subject called observers or listeners.  This pattern is an excellent example of loose coupling, because our classes can interact with very little knowledge of each other.

(read about the pattern @ http://en.wikipedia.org/wiki/Observer_pattern )

This post will demonstrate the usage of this pattern in ColdFusion

In the example I am creating a user list and the list if being watched by a logging observers that prints the message out to the browser anytime the new user gets added
(more…)

1 comment April 14th, 2008

Exploring Data push with Instant Messaging

Have you ever come across the idea of building an application or functionality that notifies the user of some event, I can think of various examples?

  • A Real estate side notifying the user that property matching their criteria just got listed
  • A job side notifying user that a new job matches there keywords
  • Application server error alert send to administrator
  • Notifying that stock prices went down or up

I can think of hundreds of different situation where notification functionality can be use, today’s most of the notification either happens though email or by the fact that user will come to certain section of site to get the updated information, not trying to downplay the fact that there are tools like nagios etc that can pull data from SNMP traps and send notification but that’s require you to implement SNMP protocol in your application which is not a trivial task.

With the every growing popularity of Instant messaging where millions of users are now actively using IM as means of communication both in office and personal environment bring a very promising platform for application development that can provide the notification mechanism that once thought was tough to implement.

Though instant messaging application like MSN, Yahoo Messenger, AOL Instant Messenger, Google Talk etc have implemented their own protocol and don’t cross communicate but there is light at the end of the tunnel. Google Talk uses XMPP protocol for messaging and looks like yahoo and AOL may follow the suite in future.
http://florianjensen.com/2008/01/17/aol-adopting-xmpp-aka-jabber/
http://www.process-one.net/en/blogs/article/after_aol_yahoo_is_also_experimenting_with_xmpp/

XMPP (Extensible Messaging and Presence Protocol) aka Jabber, is a light weight XML based messaging protocol for which various libraries exists and can be used for application development. If all the IM application start supporting XMPP the application development for IM platform will become super simple, but that not the case yet and I think it’s going to be a while before something like this will happen. (more…)

Add comment March 28th, 2008

Webservices AxisFault Handling in Coldfusion 8

Day was going fine, had my morning coffee attended project related meeting by the time I got back to check the mail I saw a chain of message going back and forth between the coldfusion developers and the backed web services developer regarding the AxisFault subject.

The issue started with the changes that backend/services team implemented in development environment, where they were throwing axis fault in error situation so that the calling application can trap that information and perform appropriate action, It was a little different then how it used to be down before. The main issue for the coldfusion developer was that they were not getting the AxisFault object back, instead in the exception object the fault data was back as a string which they parse and search for the error code and description.

After having the discussion with both the group it was clear that services team wanted to keep the functionality but for frontend/coldfusion team it was additional burden for parsing string and looking for information.

axis_4.JPG

(more…)

Add comment February 7th, 2008

Using CFQuery for executing stored procedure

Something that all of us wants to avoid is server slow down and crash in the event of application load and that’s what motivates us to look at code optimization, refactoring, frameworks, database optimization etc.

There are various steps that can be taken for application optimization and to have uninterruptible application availability, but for the moment I am just going to focus on database side. This wont be the first time you are hearing about database/query optimization for having a healthy application, and assuming you have the best optimization done there are still times when unthinkable happens i.e. network connection to database is slow, database transaction log is full, query is running without using a index etc. The point being unforeseen issue can happen with database and it can bring your site to its knees, and your customers have to suffer.

Many of the large scale application uses stored procedure instead of inline SQL queries in CF code and therefore CFStoreproc tag is the ideal choice for running Stored procedure. But one of the biggest disadvantages of using CFStoredproce is the missing timeout attribute, which can lead to slow sites and complete crapping out of server. For whatever reason if the stored procedure executing time goes up then normal expectancy its going to slow down the page processing and eventually result in request queuing for high traffic site and the unavailable server crash.

(more…)

Add comment January 2nd, 2008

Prototype Pattern in ColdFusion 8

The prototype means making a clone. This implies cloning of an object to avoid creation. If the cost of creating a new object is large and creation is resource intensive, we clone the object. This article explains how this pattern can be used in coldfusion

I set out tonight to determine if the Prototype design pattern would be useful in object factories in ColdFusion 8. The Prototype pattern, in a nutshell, is to create a new instance of an object by copying an existing object instantiation. The object to copy is an object instantiated once and then used as a blueprint for future objects of the same type. The thought is that copying an object holds a lesser cost than instantiating a new object.

Read the full Article

Add comment December 26th, 2007

DAOs and Gateways in ColdFusion

Brief introduction of DAO and Gateway pattern for coldfusion audience

Data Access Object and Gateways are the names given to ColdFusion components that access information from a database or other external data source. Within the ColdFusion community DAOs and Gateways have pretty much taken on the meaning as follows

Read the full Article

Add comment December 22nd, 2007

Object Factory in Coldfusion

Factory method pattern implementation in coldfusion along with working sample code, This pattern helps to model an interface for creating an object which at creation time can let its subclasses decide which class to instantiate.

For those of you new to this concept, an object factory is nothing but a component whose sole job is to create components. An object factory is quite simple and small. Its main role is to collect the information necessary to create an instance of the intended object’s class and then to invoke that class’s constructor

Read the full Article

Add comment December 16th, 2007

Command Pattern in Coldfusion

Object in command pattern are used to represent action and can be used effectively in coldfusion, this Article explains the command pattern by building a demo application.

The tutorial is simple in its presentation but gets the job done and includes a full working application putting everything to good use. You’ll be creating a home automation Remote Control for the appliances in your house. My remote has simple on/off buttons and and undo button but the tutorial will teach you to do more

Read the full Article

Add comment December 10th, 2007

Implement the State pattern with ColdFusion Components

State Pattern implementation in coldfusion to maintain the various state of an object. The article provides step by step implementation along with downloadable code for future reference.

The introduction of ColdFusion Components (CFCs) in ColdFusion MX opened the door to more object-oriented programming in CF. When application developers start thinking about OOP, the idea of design patterns almost always comes up. In that context, Brian Kotek discusses the State pattern: its purpose, the problems it can solve, and how you can implement it using CFCs.

http://articles.techrepublic.com.com/5100-3513_11-6167539.html

Add comment December 4th, 2007

Older Posts


 Subscribe in a RSS reader

Categories

Links

Feeds

Tags