Design patterns

  • Really enjoying the Design Patterns series :)
    I’ve always thought of those old GOF patterns as being kind of ployfills for stuff that C++ wasn’t good at doing.
    When I got (back) to JS after a decade of working with class-based languages (AS3 and Java), I was kind of surprised that I didn’t feel a need to use any of those patterns.
    I was relieved, actually :)
    Instead, it seemed to me that a lot of those patterns had analogies in basic JS usage, like this:

    Singletons: Object literals.

    Decorator and Factory Patterns: Basic functional composition (or mixins).

    MVC: … possibly not needed if you’re using a event loop (like setInterval or requestAnimationFrame) to check and respond to property changes in objects over time.

    Does anyone else out there have some easy JS cheats for GOF patterns?

  • LDG

    Thanks! Some of those design patterns can be a bit much, I agree. I’ve heard lots of critique about Java and Factory pattern abuse.

    MVC is interesting for games, I think. The game simulation would be the model, the rendering is an observer which draws the model, and separate code to handle user input and update the model. This works well with turn based gameplay, especially.

  • Tiger Hat

    Be sure to check out this helpful free resource @d13

    It touches on much of what @geoffb has been talking about.

Log in to reply