Home > ActionScript, Design Patterns, Examples, Flash, Flex, OOP > Where's the Real World?: Design Pattern Examples in ActionScript 3.0

Where's the Real World?: Design Pattern Examples in ActionScript 3.0

Gentle Readers: This short post is a request for feedback. The whole issue of appropriate level examples both in our books and this blog is an important one because it speaks to the utility of the writings and posts. So, your thoughts are not only welcomed; they’re essential.

I had a meeting with a computer scientist who was teaching a game class. In our short chat, he must have used the term real world a dozen times. Well, I’m all for the real world (in contrast to the unreal world of unicorns, fairy dust, and honest politicians). However, the real world for one is not the same as it is for another. Recently, I got a comment about a blog entry thanking us for a solution to a practical problem that one of our readers encountered in programming. The same post was criticized by another reader as not being real world. Therein lies the dilemma.

Abstract vs. Concrete

Chandima and I use a range of examples in our book. We start with an abstract minimalist example so that the reader can see the participants in a design pattern and then move on to something more concrete to illustrate a practical application. On this blog, most of the examples start with the more abstract elements and move into a fairly general (somewhat abstract) example that is more practical. The more abstract an example, the more general its applicability—not unlike an abstract class. However, the more concrete an example, the better the reader can use it to model a like problem in an eminently practical way. Each has its benefits. The abstract examples have generalizability and the concrete examples have needed detail.

Were I to do all of my examples using real world examples that I deal with, most would involve streaming video and Flash Media Server. My customers usually approach me for just that kind of problem. Obviously,using streaming video and FMS is real world, but its not very generalizable. Likewise, some readers complain that the abstract examples don’t help because they’re not practical.

We’d like your thoughts on this issue. Obviously, the most useful examples would be those that you deal with directly in your work, but like my practical work, it’s pretty narrow. Keeping these concerns in mind, tell us what’s most helpful to you.

Share

Related posts:

  1. Take a Design Pattern to Work Part I: Identifying the Problem
  2. ActionScript 3.0 Memento Design Pattern: Flash Media Server 3 Application
  3. ActionScript Proxy Design Pattern : The Virtual Proxy (A Minimal Abstract Example)
  1. Marien
    January 26, 2009 at 3:47 am | #1

    I think most of the time people are looking for solutions right out of the box, which works like downloading a .zip, extract it, adjust it a bit and there you go, a nice app which uses design patterns wow…
    But i think it’s vital to understand what’s really happening, which means that you actually have to read a book (this one when it comes down to DP in AS3) and play with the examples and adjust them to your own ideas. I’m right in the middle of reading/playing with this book and DP in general and i’ve made my own sort of small library with the examples used in the book. But i’ve made them myself which is far better than just download some examples.
    And after reading & understanding this book you should be able to make your own real world apps and see if a Design Pattern is actually needed for the given project.

  2. January 26, 2009 at 11:04 am | #2

    Marien,

    I couldn’t agree more. At some point, one does have to make a design pattern their own. If you don’t understand what is going on, a cut and paste might actually cause more problems than it solves.

    I believe we’re looking for the best level of abstraction so that readers can do as you suggest.

    Thanks,
    Bill

  3. seren
    January 27, 2009 at 4:20 am | #3

    I think everyone learns differently. Personally I prefer more concrete examples because its easier to make associations. Generally if you experience any kind of problem in life, you will associate that problem with similar experiences in order to find a solution. Not that one size fits all (thats a lazy programmer) but its a good starting point.

  4. jadd
    January 27, 2009 at 4:23 am | #4

    Hi Bill,
    and thanks for your book and work. We all need real world examples and not only zip files. The real problem to me is that the DP are skeletons and often I’m in trouble trying to convert them in useful and reusable code and most of all combining them. The distance from theory to real to me is scaring. That said, I would like to build a pure As3 flash site, the first problem is usually preloading, then navigation, then content. Are there a DP who fit?. Can you help me/us to go in the right direction?.
    Thanks. Jadd.

  5. January 27, 2009 at 6:10 am | #5

    Hi Seren,

    I guess the problem lies in which real world you mean. As I noted, most of the stuff I do in terms of real world is streaming video using FMS with Flash or Flex. So while I can provide a real world example with that, it’s not the same real world that you may be looking for or understand. As long as you stick with video, then it’s ok, but when you move to different areas where you might want to use DPs, it’s no help at all.

    Maybe we ought to get a list of common projects that our readers build and talk about general yet concrete examples of some of these projects.

    Thanks,
    Bill

  6. January 27, 2009 at 6:18 am | #6

    Hi Jadd,

    The more we understand the theory the more generally we can apply and use DPs effectively. I think that Marien’s point about taking the different design patterns and creating libraries of DPs with examples pertinent to your own projects is the way to go. Then you have a set that’s both general and specific.

    Your comment did give me an idea, though. You said,

    The distance from theory to real to me is scaring.

    We might begin to think of the examples as the bridge between the theory and concrete. They should be general enough to be applicable and specific enough to provide needed details.

    Thanks for your thoughts,
    Bill

  7. January 27, 2009 at 7:47 am | #7

    Hey Bill –
    First off, excellent work.
    The method you discussed, an abstract example followed by a “real world” example is very helpful. I feel it’s the difference between learning and mere replication.
    Something that I’ve always liked when teaching new developers, is to put them on a project that deals with multiple concepts. Teaching them each individual concept simply, and using a single project to illustrate how they all integrate together in a real world example.
    Frequently I found developers would understand a basic concept, but when introduced to “real world” code, they wouldn’t be able to identify the borders of concepts. Where one tool ends, and the next one begins.
    Best of luck,
    Sean

  8. January 27, 2009 at 3:28 pm | #8

    Hi Sean,

    You and I are in the same boat as far as new developers understanding basic concepts but not how to apply them away from a single example. It turns out that this is not only a problem with learning programming, but in general where you have a theory-practice dialectic. My wife teaches research methods to university students in Social Work. She tells me that everyone is very happy with a concept or a concrete example and seem to understand them both. However, when the concept is applied or the concrete example is expanded to a wider area, the wheels start falling off the cart.

    With design patterns, this can be especially tricky even though they are general patterns designed for particular classes of problems. I’m trying to adopt a mindset of the “middle region,” where we can tie the abstract and concrete together. Your technique of having multiple concepts in a single problem is a good idea because it shows the universal nature of both the process and the concepts.

    Kindest regards,
    Bill

  9. January 29, 2009 at 6:14 pm | #9

    Perhaps the method to approach this kind of user-understanding problem is to just give them the problem, let them work through the problem, get the results back, then explain why their method is wrong ( and have them explain what you identify as correct). Then rinse and repeat. This will give them a better understanding of the methodology, and a sense of accomplishment once everything is as good as can be. I like to puzzle through issues, but getting a few “you may want to try this” is always a welcome addition (as long as it’s constructive)

  10. January 29, 2009 at 7:30 pm | #10

    Hi Gareth,

    Had I but the patience of a saint… I certainly see your point and its inherent value, but that’s a lot of work! Also, it assumes that I may understand an area better than someone who’s toiled in a particular field for some time–but sort of in reverse. If I pose a problem, I’ve got to know enough about it to add the necessary details, and therein lies the irony. The more details I add, the more it moves away from a general problem to a highly particular and specific one.

    In the comments section of this blog I’ve suggested that readers follow up on comments they’ve made to try it out. On only a very few have I ever got a response like, “Hey, let me go work that one out!” Everyone has a better algorithm or “trick” but those are usually for a specific problem or what the Freemans call a “Programming Idiom.”

    Let me make this assertion: Most ActionScript 3.0 programmers do not think in terms of the larger structures represented in design patterns. At the same time these are very smart people; so maybe the quest is to how to help, encourage and launch ActionScript 3.0 programmers into a wider mindset that includes thinking more about relationships than algorithms.

    Thanks for your great comment,
    Bill

  11. January 30, 2009 at 4:57 am | #11

    For me the best ‘real-world’ examples are ones which don’t require me to install/learn anything new (and certainly nothing proprietary … even if it has a demo).

    I’d be happy to see examples that didn’t depend on anything other than core components and AS3. As long as the post concerns a realistic scenario, that’s enough for me. Your most recent post (Iterator Pattern Example: Developing a Webpage Scraper) looks to be spot-on.

    Cheers,
    Neil

    • January 30, 2009 at 10:42 am | #12

      Hi Neil,

      I agree there. Clear, applicable and nothing outside of the AS3 domain. That’s probably as good a starting point as I can imagine.

      Thanks for the comment,
      Bill

  12. Curro
    February 4, 2009 at 1:15 pm | #13

    Hi everybody,
    I am reading the book(as3dp)and have read the series on the Factory Pattern and I find the examples really useful. It is true that they are not “Real World” examples but they make the pattern understandable. I have tried the GoF book several times and have had to give up because I could not “visualize” the concepts. Now at least I understand some of the patterns and their utility.

    I have read other books about design patterns but their examples were not as appropriate as the ones discussed here. They didn’t make the patterns so clear.

    I am trying to apply the factory pattern to a small Quiz application with very different types of questions(from “fill in the gap” to “drag and drop”) Up to now what I had was a collection of five or six types of quiz and every time I thought of a new kind I had to rewrite all the (very similar)scoring logic once and again for every type of question. Now I hope to have one for the whole quizzing stuff no matter what type of question I devise. It is not much but it is better than nothing.

    Life is a lot easier. Which is the whole point.

    Thank you

    Curro

  13. February 5, 2009 at 3:25 am | #14

    Hi Curro,

    You happened to pick a chapter I really like (Chandima wrote it), and it had the same effect on me. Starting with an abstract example, Chandima worked out different more concrete examples of the Factory Method pattern. In working out the “Take a Design Pattern to Work” posts, I was able to quickly wrap my head around the Factory Method because of one particular example Chandima had made. With it I was able to go North and South——North to more precise elements in an example and South to the wider concepts involved.

    Maybe you’d like to share your class pattern in the form of a Class Diagram using the Quiz you created? That might help others see a solution from a different perspective. Like you said, whatever makes life easier.

    Take care,
    Bill

  14. Curro
    February 11, 2009 at 11:12 pm | #15

    Hi Bill,
    It’s been a time since I wrote the comment above yours.
    As soon as I read yours I began to draw a class diagram of my Quiz but I soon discovered that I had not implemented a Factory Method pattern but a costly inheriting mechanism. I tried to add another type of quiz and saw I had to rewrite the super class to fit it in.
    The case is I am new to AS3 and am learning it along with design patterns. I think I am not ripe enough for them but I also think it’s the way to go.
    As soon as I find a decent solution to my problem I will let you know. Maybe it will be a Factory Method pattern but it could also be a Strategy pattern.

    Thank you for your patience
    Curro

  15. February 12, 2009 at 2:27 am | #16

    Hi Curro,

    You know, you don’t have to gobble up all of the Design Patters or OOP principles in one bite (or byte) but instead take just a little taste here and there. We plan to be thinking about and improving on our knowledge of design patterns and AS3 for a long time. So whenever you feel like it drop on by and tell us what you’re up to.

    Take care,
    Bill

  16. Ian Kinsey
    February 18, 2009 at 4:21 pm | #17

    Hey Bill,

    I’ve read your book, and I’ve found about 75% of the stuff that you say useful so first let me say thanks. I had to respond to this post — even if it is a bit late — because I think the one thing that would make your book and your blog posts more useful is more concrete and explained examples. I read a blog you linked to in another one of your posts http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/ and I think the kind of example he gives is perfect. It’s concrete, stays abstract by keeping irrelevant issues black-box, and contrasts the what-to-do with the what-not-to-do.

    If there’s one suggestion I have for your future books it’d be that you include more concrete examples. Even if you want to use FMS streaming media as an example, just use the part of the code that’s relevant as an example and keep the rest of it black-box. Again, I think that post on Misko’s blog is a perfect example.

  17. February 19, 2009 at 4:01 am | #18

    Hi Ian,

    Thanks for your thoughtful comment. You’ve made an excellent point, and I certainly know what you mean by Miško Hevery’s examples. Sometimes we can nail an example in exactly the way you describe, but other times we think we’ve got it exactly right, and someone writes us and asks, “What the…?” and someone else says, “That’s it!! Wow! Thanks.” Go figure.

    Both Chandima and I work with both university students and professional developers (and clients) and I suppose what we try to do is to provide several examples along two different lines. One tact is to provide fairly abstract examples so that the overall structure of a design pattern is revealed. That is so readers have a general sense of what a design pattern is attempting to accomplish. Some such examples can be found in the widely praised book Head First Design Patterns. (If you have the book, take a look at the chapter on the Strategy pattern and the flying and quacking duck example. Hardly something we’ll ever see in reality, but great for getting points across.) The other tact is to try and select a real world example that does several things, First, the example must clearly show how the design pattern is useful for that particular example–or more general task. Some examples do work with a particular pattern, but they’re not particularly good for revealing what the pattern does or showing why it was selected. Second, the example must be universal enough that readers can see its relevance to their own work. Finally, the example needs to be a typical use of ActionScript. In the same way that LISP users expect to see some example relevant to AI, I think that ActionScript users expect to see a typical Internet example with the tools originally developed in Flash. (Yes, I know that is changing rapidly, especially with AIR–so we have to choose examples even more carefully.)

    However, no matter what, we’ll always get surprises. At the Montreal OOPSLA meeting a couple of years ago I presented a Flyweight example using a radar simulator much like the one on this blog. At the end of the presentation, one guy asks about a “real world” example, and everyone at the session turns and looks at the guy like he’s a moron and say, That is a real world example! So even though just about everyone gets it, some do not see the usefulness or relevance of a particular example. That’s why we have several examples for each pattern in our book. On our blog, sometimes we’ll have a single example and other times we’ll have several. That usually depends on what we’re working with, the time we have and reader interest.

    Anyway, it’s a topic we think about a lot and try to improve on. Your particular comment is extremely helpful because you provided a good example in Miško Hevery’s work.

    Kindest regards,
    Bill

  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>