"ActionScript 3.0 Design Patterns" a good place to start for Flash developers

If you’re looking to improve your coding practices, and earn that “Engineer” part of your title, design patterns are a good thing to know. I recently picked up a copy of ActionScript 3.0 Design Patterns by William Sanders and Chandima Cumaranatunge. With Flash 9 bringing more developer-friendly improvements to ActionScript, and Flex making waves in the technology world, now’s a great time to become a better developer. I know a few design patterns well, but I know that I have many more to learn. If you’re unfamiliar, design patterns offer recognized and accepted solutions to the common project requirements. This book, we’ll call it AS3DP for short, gives a good foundation for a growing developer.

AS3DP is divided into several sections based on a basic categorization of design patterns. These categories have been defined previously in other important texts about design patterns, and I’m glad that the authors chose to stick with the precedent. They appear as follows.

  1. Creational patterns

  2. Structural patterns

  3. Behavioral patterns

  4. Multiple patterns (more than one pattern combined into one)

The section on Creational patterns starts with the Factory Method pattern. This pattern is explained very well with two interesting examples. The first example, a Print Shop, helped me understand the problem and solution very easily, and the second example, a shooter game, was a fun way to reinforce the knowledge. Next, the Singleton pattern is introduced. This pattern is an obvious choice, as one of the more common ones I’ve seen mentioned by ActionScript developers, and the section includes good material.

We go next into Structural patterns. I found the Decorator pattern, again, very easy to understand. The examples in this section illustrated the purpose well, but they didn’t quite catch my interest as the ones in previous chapters. Paper dolls probably won’t appeal to the average target reader of AS3DP. Decorating with “Deadly Sins and Heavenly Virtues” seemed weird too. I would have preferred the focus to have been closer to real-world projects as much as possible. The Adapter pattern is another well-explained pattern. The example of easily controlling a car in different ways (such as through code or the mouse) brought my interest back a bit. This section ends with the Composite pattern which is explained through the Flash display list (an excellent choice to help the reader’s understanding) and inverse kinematics, another interesting topic.

The third category of patterns features Behavioral patterns. We start with the Command pattern. One example implements undo, and another sets up controls for a podcast media player. Much to my annoyance, the authors decided to include the Observer pattern. Considering that they don’t have an exhaustive list of the classic patterns in this book as it is, I don’t understand why they decided this one is important to include. One of the native classes in Flash Player, EventDispatcher, already uses this pattern. To be blunt, very few developers will ever implement the Observer pattern in AS3. The Template Method pattern was easy to understand, and the examples summed it up well. Overall, he State pattern was introduced very well and I found it understandable. The video player example could have used a little more work, I think. I understand that simplicity is important for examples, but something felt strange about a video player that couldn’t go directly from a paused state to a stopped state. Behavioral patterns end with a look at the Strategy pattern.

The final category of design patterns introduced in AS3DP is the set of patterns that combine multiple patterns into one. The first is Model-View-Controller, or MVC for short. Along with Singleton, this is one of the most common patterns that seems to appear in ActionScript code. The examples for this one were generally interesting, and it was a good review for me. The finally pattern is Symmetric Proxy. It seemed to be explained pretty well, and the authors warned the reader that it has some minor changes from the traditional implementation which was thought-provoking, and I think it will act as a subtle suggestion to help readers explore design patterns a bit more. The requirement of Flash Media Server and its AS1-style code to create the example was a bit of a turn-off for me, though.

I found ActionScript 3.0 Design Patterns to be a book that I could read from start to finish. Often I will skip sections in books that cover material I already know, but design patterns are generally pretty flexible, and it was nice to see the authors’ perspectives on them. I also had motivation to continue on because there were several patterns I haven’t yet used in my projects, and I love to learn new things. Some examples were very good and kept me interested; others felt completely out of place. In general, all of them helped me to understand how the patterns should be implemented.

If you want to learn design patterns, I think AS3DP is a good place to start if you’re most familiar with ActionScript over other languages. You may want to pick up a more general book about developing with design patterns later, though. The authors didn’t include all of the classic design patterns introduced in the original source, Design Patterns: Elements of Reusable Object-Oriented Software, and it’s probably a good idea to go beyond what’s presented in AS3DP. I’ve also heard good things about the book Head First Design Patterns, but I haven’t read it myself.

About Josh Tynjala

Josh Tynjala is a frontend developer, open source contributor, bowler hat enthusiast, and karaoke addict. You might be familiar with his project, Feathers UI, an open source user interface library for Starling Framework that is included in the Adobe Gaming SDK.

Discussion

  1. Bill Sanders

    I enjoyed Josh Tynjala’s comments on our book, and we’ll take to heart his ideas if we revise or update it. In the meantime, we’ve been working on more ActionScript Design Patterns on our Blog at http://www.as3dp.com/. We’d like to include more design patterns and have started doing so either with more examples of the ones we had in our book or ones we left out, like the Flyweight pattern. The Blog has lots of comments on different aspects of Design Patterns an we welcome more comments and input like Josh’s.

  2. chad

    based on your comments, you’ve been utilizing MVC without the Observer pattern. if you’re dealing with ongoing data changes that affect the view, the Observer pattern should be your best friend.