It’s Already 2008
*Note: This is just for reader comments.
As we forge ahead in the new year, we’d like to add useful Design Pattern material to this blog. Right now, the plan has been to add design patterns that we did not cover in our book. Our book covered the following:
Creational Patterns
Factory, Singleton
Structural
Decorator, Adapter, Composite
Behavioral
Command, Observer,Template Method, State, Strategy
Multiple Patterns
Model-View-Controller, Symmetric Proxy
Our blog so far we have included detailed descriptions and examples for:
- Composite
- MVC using the PureMVC framework
- Flyweight
- Chain of Responsibility
- Memento
- Mediator
One goal is to have a complete set of Design Patterns in ActionScript 3.0. Moving toward that goal, I’ve been going through the “Leftover Design Patterns” in the Head First Design Patterns book finding ones that I’ve not seen in ActionScript 3.0. For me, at least, it’s more interesting than ones that have already been done either in our book or elsewhere in ActionScript 3.0. Currently, that leaves the following list of “leftovers” that we’ve not examined:
- Bridge
- Builder
- Interpreter
MediatorMemento- Prototype
- Visitor
There are other Design Patterns as well that were not covered in our book, but the leftover list seems to be a good starting place. So, that being said, we’d like to know how you’d like us to proceed. Rank the following from 1 to 10 (1=No thanks … 10=Yes, I want that!). Place your rankings in the comments section.
1. Keep working our way through the “Leftover list”. (Include which Design Pattern you’d like to see next.)
2. General discussions about design patterns and their concepts (e.g., relations between patterns, different alternative pattern designs, OOP concepts found in design.)
3. Simple abstract examples to best see the structure and concepts involved.
4. Design pattern examples with practical application examples even though they are more complex and do not as clearly show the structure and concepts.
5. “Head” discussions about different ideas for programming in ActionScript 3.0 for OOP and design patterns but not any particular design.
6. Preference: Flex, Flash, Both
Also, if you have other ideas you’d like to see included on the blog, just add them to your comments.

I’d like to see more about the Data Transfer Object pattern as it pertains to both the client-side (Flex) and usefulness of its implementation in service layers feeding Flex applications.
Often, it’s not ideal to send business objects in their natural state down the wire, especially in RemoteObject situations: object graphs and circular references present serious issues. In this situation, DTO provides a solution in that its a representation of state targeted exactly at how state should be sent down the wire.
I’m super familiar with it on the server-side, but I’d like to see more about dealing with it on the client-side. I often see smaller Flex apps that deal with nothing but DTO implementations (Value Objects), but as applications grow, the VO’s may need to take on more logic, at which point I’m not sure what I should do: add stuff to the VOs directly? Develop a true client-side business model that models client-side behavior of these objects and populate this model from VOs (as I’d do on the server side?
Hi Joe, you make a very timely point. I’m working on a Flash Lite game developed on top of the PureMVC framework and I’m struggling with exactly the issue you bring up - where to put the logic? I’m not sure if you have taken a look at PureMVC, but it has a solution where VOs are accessed through proxies and logic is encapsulated within commands and proxies.
Handling state is another huge issue that we are working through. I’m sure that you can provide some valuable input to this discussion at:
http://forums.puremvc.org/index.php?topic=195.0
You may also be interested in checking out this PMVC sample Flex app developed by David Deraedt. Shows how to map local VOs to a remote service:
http://www.dehats.com/drupal/?q=node/26
Hi,
I would suggest the following precedence of investigating and implementing design patterns in AS3 (at least those are the ones that i’m familiar with but would like to further investigate them):
1.Memento
2.Bridge
3.IoC
For some of those (also for ones not included in the ‘leftovers’ section) I’ve got real-life practical examples in Flex / Flash.
Cheers,
Petro
Petro,
Not sure what #3 –IoC– is.
I believe that I’m not the only one thinking that it would be great to have some of these examples integrated with the Flex Framework or in use with UIComponent(s). As opposed to only AS3.
I’m guessing most of the people following this blogg or reading the book are actually going to implement this stuff within the Flex Framework, creating components from scratch by extending UIComponent or extending other Flex components.
Hey Bill,
IoC = Inversion of Control, a.k.a. Dependency Injection. It’s the core of frameworks like Spring and Guice.
It’s less of a design pattern, more of a school of thought: instead of having a class use a concrete implementation of another class, have it rely on an interface implemented by that concrete class. Then, use a container (such as Spring) to “wire” in the concrete implementation to use at runtime.
I do this with delegates in my Flex apps: if I have to read Contact instances from a service, I rely on IContactDelegate. Based on runtime configuration settings, I have a factory that provides a specific implementation: RemoteObjectContactDelegate may be an implementation using ColdFusion or BlazeDS, while MockContactDelegate may just “fake” having a server there so that I can develop independently of the back end.
-Joe
Hi Thanks Joe,
I was going through the DPs like a man possessed wondering what I missed. Now I can sleep tonight.
One of the little things I was going to write was to be called “No New is Good New”–avoiding the use of new and using alternatives approaches. It may be related to IoC from what you say, and it sounds very exciting. I got the idea from the Freemans’ book and was going to follow up from there, but now I know I’ll go searching for more on IoC
Thanks again,
Bill
I’d like to see some Flex example in ‘real life’. For example I’ve implemented the Decorator pattern for a popup window decorated regarding the context (editing, adding …), in other words a good example?
But when the job was done I’m not so sure Decorator was the good choice.
Your analyse + real life example == good job
Thxs (very good book)
Laurent,
You know, that’s a good question. How do you know that the choice you’ve made as far as a DP is concerned is the right one. I liked the State DP when I did a video player because the video is so clearly state driven. However, I’ve seen good video players using MVC; so that’s a great issue to broach. That might be a good topic to kick around.–How to determine whether the DP you’re using is the best choice.
Thanks,
Bill
My latest DP incursions have been into the world of the Mediator Pattern. For the love of God I do not know why I had not taken a look at it earlier. The combination of Strategies and Mediator is arguably as powerful as the MVC.
*By the by I do have my misgivings about PureMVC but I am reading Chandima’s note on the subject before I make up my mind
Hi aYo,
Next up will be the Memento, which is a very interesting DP for preserving state. Following that will be the Mediator, which, I agree is a very nice way to handle a lot of different algorithms while decoupling them from their objects.
I’m going to use the Memento with an online course system I had to put together when I broke my leg in October and couldn’t go to the bricks and mortar. The Memento will allow me to preserve a “place” in the video and slide show so that the user can stop where he wants and then go back without losing his place.
I think after reading Chandima’s piece on PureMVC, you’ll have fewer misgivings.
Bill
Memento sounds nice. Always intrigued me the name, a bit like some horror/thriller but, it is actually a nice pattern I have deployed on occasion. Chandima’s piece is very illuminating but, my reservations remain. In truth, his treatise is probably the best illustration out there on the use and understanding of PureMVC. What evades me is the WHY? You know I’m up for experimentation as much as the next guy, in fact many a time you have had to rein me in. I can see a myForum2 discussion is needed, we should get Chandima to join in as well, eh??
aYo,
Every spare minute I’m spending with the Memento. In some respects it’s very simple, but in others I found some subtle complexities. It’s one of the few DPs where you don’t find some kind of interface–either an interface or abstract class. Lots of time can be spent on it. For what I want to do with it, an e-learning application with video and Power-Point like graphics/text, may take some time. However, if I get a decent abstract minimalist example together, I may put it up separately.
As for chatting about PureMVC–Chandima is definitely the go-to guy on it. I’d be a third wheel and either myForum2 or Quad (http://www.sandlight.com/quad) are good places for 4-way AV Chat. Let’s set it up with a time we can all be there. You and Chandima can chat and I’ll listen! With an extra seat, we could invite someone else who’s interested.
Bill
Just a few thoughts:
I like Petro’s order mentioned above. If you’ve covered Command, Memento is a natural progression. And Jesse Warden had a nice explanation/use of Bridge a while ago, could be a good starting place.
The best IOC example I have seen yet is employed in LOWRA, a framework made by the creators of PixLib (another outstanding framework).
Lately I’ve made heavy use of the HIVE framework (open source), that employs State pattern throughout, and have realized that UIComponents for PureMVC could be made to be state-based fairly easily with the addition of a StateManager. That would be an awesome experiment.
Ayo - did not mention what the misgivings with PureMVC are. Is it with PureMVC, or MVC in general? This methodology has been around a long long time. I hardly do a project without it in one form or another. Three things are inescapable: all applications must have data, all lapplication must be able to manipulate the data, and they must all have a way to present the data to a person. MVC just seeks to create a clear distinction between these responsibilities.