Design Patterns (Information Technology, Programming, Tech Made Simple)

Paul M. Foster (08 February 2012 23:58:55 Revised )

Design Patterns are Way Nifty Kewl patterns of code which are supposed to facilitate certain types of operations. (Was that sarcasm you detected? Yes it was.)

For example, the Singleton pattern. Let's say you had a configuration class that held the configuration values for your application, and you wanted to make sure there was only one object of that class instantiated, no matter how many times it was called in your code. You'd arrange the code and call the class in a certain way to ensure that only one object of that class resulted. To make your configuration class a "singleton", you'd probably make the class have a *private* constructor (so no outside routine could call it), and then provide a method called get_instance() which tested for the existence of an object of that class. If such an instance was found, someone calling configuration::get_instance() would simply get the existing object returned to them. Otherwise, configuration::get_instance() would instantiate the class and then return the new object to the caller.

As you can see, that's a peculiar way of setting up your code for a specific purpose. Other design patterns do other things and dictate setting up things in other ways.

The definitive work on this (and where it first gained the most publicity) is a book called "Design Patterns" by four authors (Gamma, Helm, Johnson and Vlissides). It essentially contains chapters about each (known at the time) design pattern and some code (mostly Smalltalk and C++) to show how it might be constructed. I imagine the authors looked at a lot of code and discovered that programmers were coming up with code that, in each case was remarkably similar for solving certain types of programming problems. So they codified what that found and wrote a book about it. Unfortunately, the book is a lot like the medicine you had to take as a kid; you have to keep reminding yourself it's good for you, even though it tastes really really bad. From what I understand, there are other, better ( = more understandable ), books on the subject now.

I have the book on my shelf, and it's decent technology, but you could spend your whole career and never use any of it, and get along just fine.