As we all are well aware, ColdFusion, historically, has been a programming language that has allowed for ‘spaghetti code‘ and poor application design practices. However, with the emergence and maturity of major frameworks, such as Fusebox, Model Glue, Mach-II and ColdSpring, there has been a shift of emphasis from poor coding, to re-usable and extensible development practices. With the maturity of the language comes the search for standard ways of achieving certain tasks. This is where design patterns lend themselves.
In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved.
Not all software patterns are design patterns. Design patterns deal specifically with problems at the level of software design. Other kinds of patterns, such as architectural patterns, for example Model-View-Controller (MVC), Implicit Invocation and Dependency Injection, describe problems and solutions that have alternative scopes. However, for ease, I generally consider software and architecture patterns under the design pattern scope.
Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns.
Design patterns can be classified in terms of the underlying problem they solve. Examples of problem-based pattern classifications include Creational, Structural and Behavioural Patterns. Creational patterns, such as Singleton, deal with the creation of objects, Structural patterns, such as Facade, deal with the relationships between objects and Behavioural patterns, such as Observer, deal with the communication between objects.
The practical application of design patterns to ColdFusion applications is a new phenomenon and one which requires careful consideration. There is no sense in using a design pattern for the sake of using it, it must first solve the problem you have encountered. Common design patterns that I have used in my day-to-day development have included Singleton, Composite, Model-View-Controller (MVC), Data Access Object (DAO), Gateway, Bean and the Facade Pattern. These I will discuss in later articles.
Alexander, Christopher; et al (1977). A Pattern Language: Towns, Buildings, Construction. New York: Oxford University Press. ISBN 0-195-01919-9.
Freeman, Elisabeth; Freeman, Eric; Bates, Bert (2004). Head First Design Patterns, paperback, O’Reilly. ISBN 0-596-00712-4.
Gamma, Erich; Richard Helm, Ralph Johnson, and John Vlissides (1995). Design Patterns: Elements of Reusable Object-Oriented Software, hardcover, 395 pages, Addison-Wesley. ISBN 0-201-63361-2.
Shalloway, Alan; Trott, James (2001) Design Patterns Explained: A New Perspective on Object-Oriented Design, paperback, 368 pages, Addison-Wesley. ISBN 0-201-71594-5.