An Awakening to Design Patterns
Earlier this month, I spent a week in Maryland working with Branden Hall at his Automata Studios. The trip was a chance to get to know each other better, and we both had a great time. We coded during the day, played Guitar Hero in the evenings, and discussed all sorts of geek topics in between. Oh, and we had terrific food every day!
I often played with Branden’s toddling son, Kai, who on more than one occasion conferred on me his “Harrison Ford grin” (mom Pattie called it that, and gosh, she’s right!). The whole experience was very welcoming and down to earth. I’ll be contracting for Automata Studios on a regular basis.
While there, I dipped into a handful of platforms and languages, including Python and an interesting variant of BASIC for PDAs. This was new ground for me, but it really wasn’t especially hard. It was reassuring to see firsthand that the principles of good programming do in fact transcend any particular language. My general interest in logic puzzles was enough to steer me through, for the most part.
At one point, Branden handed me the O’Reilly Head First Design Patterns book, to take home and borrow. The book was written for Java, but ActionScript 3.0 is close enough, and honestly, much of the content is plenty applicable to AS2. I had heard of design patterns years ago, but they were just another “one of those things” that didn’t especially register. I would occasionally see them either heartily praised or heartily criticized in various forums, and I vaguely got the impression that people tend to either love them or hate them.
A couple chapters into the book, and I have to say … I’m liking what I see.
Coincidentally — and here’s the interesting part, I think — I just finished reading Ambient Findability, by Peter Morville, and number of Edward Tufte’s works (Visual Explanations, Envisioning Information, and The Visual Display of Quantitative Data) for a current freelance project. On a conceptual level, these books all hover around the same sorts of good advice — how to best express a complex set of ideas. You could say the authors would have a decent time jamming together in a band. Sometimes, in a very nice way, when it rains, it pours.
In one of the Tufte books, he describes a kind of graph / data plotting mechanism I’d never seen before, a stem-and-leaf plot. It took me a moment to grasp how the thing might be useful, but when I “got” it, I thought it was pretty neat.
For example, the following numbers …
54 56 57 59 63 64 66 68 68 72 72 75 76 81 84 88 106
… would be rendered in a stem-and-leaf plot like this:
5 | 4 6 7 9
6 | 3 4 6 8 8
7 | 2 2 5 6
8 | 1 4 8
9 |
10 | 6
Note the vertical divider. The left represents the tens column, and the right represents the ones. The first line, then, would be interpreted as 54, 56, 57, and so on. The 90s column is empty, since this set has no numbers in that range. The plot is condensed, yet manages to display not only the whole set of given numbers, but also provides an at-a-glance view of which tens group contains the most numbers (the mode average), as well as a handy histogram of each tens group compared to the other.
Sure, nothing here is earth shattering. It’s just … well, elegant. Something to file away and maybe use one day.
And boom! That’s when it occurred to me that design patterns (for me, at least) fall into the same category of “neat, that’s interesting; I’ll keep that in mind.” So check out Head First Design Patterns if you regularly write your own class files, especially classes that comprise what might be called a framework, even if it’s a small one. I’m interested in hearing people’s thoughts on design patterns in regard to ActionScript.
November 6th, 2006 at 8:56 pm
Although what I am about to post isn’t exactly ActionScript specific however I do think that it’s neat and interesting. I am fairly new to design patterns and I am very eager to apply a MVC (Model, View and Controller) paradigm to my upcoming project. I believe what is so neat and interesting about this triad is for the reason that they operate similar to the three branches (Executive, Legislative and Judicial) of the US government. It’s the separation of powers that will hopefully guide the architect (the developer) into designing elegant code.
However, from what I have read, I understand the MVC is an overkill for small projects and is a little cumbersome when modifying. My upcoming project would probably be considered small however I will still use this MVC paradigm, I would rather start on a small project versus a large one.
November 7th, 2006 at 9:51 am
myIP,
I like your analogy! You may want to check out Colin Moock’s Essential ActionScript 2.0, if you haven’t already. The book is split into parts, and Part III features a number of design pattern examples in AS2 — MVC is among the bunch.