Thursday, September 09, 2010

PatternCraft – Command Pattern

PatternCraft is a series of video tutorials that use StarCraft references to teach Design Patterns.

This video is the third in the series and covers the Command Pattern.

Other PatternCraft tutorials:
Mediator Pattern
Visitor Pattern
Memento Pattern
State Pattern
Strategy Pattern

Source is here:


  1. video player scrubbar doesn't seem to respond to touch events on Android

  2. Nice video as always John! Is there any performance benefit to using a callback function instead of an event listener or signal to notify CommandList of completed command?

  3. I get why you'd need this in JAVA, but in AS3, why not just make a closure? It's basically the same thing anyway? e.g. commands.push(function(){scv.attack()})

  4. Ricardo Schalch6:05 AM

    thanks thans thanks !... for a thousand years I´ve been looking for design pattern tutorials ... great idea make the analogy with starcraft 2 !

  5. As you said in the video, the ICommand interface is the most seen in the world. In Java, command framework is built-in. You have all you want (ICommand, ASynchronousCommand, Sequential, Concurrent, Queue, Undo, etc...), ready to go. In as3 you don't have nothing yet. I think Adobe must include basic pattern in the core of the langage. What do you think ?

  6. johnlindquist6:33 AM

    Good question :)

    It's fairly common for Commands to have a few extra features like complete/cancel/undo/fault/etc. So you'll need a Class that wraps the closure and all the extra options you may need.

  7. johnlindquist6:34 AM

    I haven't looked at the benchmarks recently, I think the answer to your questions depends on flash player version, OS, etc, etc. is a great resource for those questions.

  8. johnlindquist6:39 AM

    If we start that discussion, I'd much rather have Adobe focus on introducing an IDisplayObject interface before we even start talking about pattern coverage :)

  9. Iki_xx8:27 AM

    It would be nice since you tagged this video with intelliJ , that you give us those shortcuts that you are using when developing.
    Also a video tutorial how to setup IntelliJ for Flex/AS3 development would be nice.

  10. Plastic Sturgeon10:53 AM

    John - this series is awesome. Probably the best demo of how to use design patterns I've ever seen. I can't wait for the next.

  11. johnlindquist11:25 AM

    Thanks, it's comments like yours that keep me motivated to crank these out :)

  12. johnlindquist11:26 AM

    I've considered that, but decided it would be too distracting from the main goal of teaching patterns. It's way too easy to go off-topic.

  13. miguelMoraleda2:20 PM

    I love this way to review the different patterns. I want to share with you this link. You aren't the first guy using Starcraft 2 to teach. :) Thank you for this amazing videos/idea.

  14. jacksondunstan3:37 PM

    Thanks for keeping these on-topic. I've cringed thinking you're about to launch into some fancy DI system or event/signal library, but you've kept it pure AS3 which has really helped with understanding the topic at hand rather than all the exotic features of various libraries and tools. Great videos; keep up the good work!

  15. Fernandodefranca2:28 PM

    Awesome! Best Design Pattern series ever!

  16. Scott8:55 AM

    Great tutorial, really easy to follow. Keep them coming!

  17. GuestFromChina_beijing12:16 AM

    loves this video tutorial!

  18. [...] PatternCraft tutorials: Mediator Pattern Visitor Pattern Command Pattern State Pattern Strategy Pattern var flashvars = { width: "720", height: "586", autostart: "false", [...]

  19. [...] PatternCraft tutorials: Visitor Pattern Memento Pattern Command Pattern State Pattern Strategy Pattern var flashvars = { width: "720", height: "586", autostart: "false", [...]

  20. linghong Hsueh12:43 AM

    Very nice! But it seems that you missed some ActionScript Class in the source code! Hope you will add them soon!