PureMVC: An Eventful Coding Experience
learning it the fun way
Developers in general have a love or hate kind of relationship with design patterns. I am suspicious of anyone who say they just loooove such and such design pattern. Mainly because patterns should appear in your life and immediately be followed by “f****, why didn’t I do things like this before!” So there should be some shame attached to discovering it, a sense of regret I guess. Otherwise you are doing it wrong.
But joking aside, patterns should always work as that new shortcut in your daily commute that you never knew existed and feel really stupid for having wasted all that time before. Meta patterns are like that too, only more so. And that’s what MVC is, a meta pattern, a jambalaya of patterns, meant to help you encapsulate your code until you feel slightly unhuman: cold and distant. But in a good way.
PureMVC: Thinking so you Don’t Have To
PureMVC is a framework that uses a jambalaya (6 patterns last time I counted) and lets you–well, sometimes forces you to– encapsulate the shit out of your code, to use the technical term. It is an incredibly simple collection of classes, that allows you to do an incredibly simple thing, and comes with an unreadable PDF file to help you understand it.
PureMVC is awesome, helpful and extremely simple. And the PDFs and drawings will all make sense once you manage to use the thing. But probably not before. Plus it’s free.
When should you use it? If you are developing something that has buttons in it, do yourself a favor and use PureMVC. If you only use Events in your code if someone is pointing a gun at you and telling you to do so, use PureMVC. If you are using forms or result sets from databases, use PureMVC.
Using it makes far more sense for more “traditional” applications where you have different sections, multiple application states, displaying section and state specific data. It breaks down a bit when you have movie clips doing most of the View bit, and by that I mean if your application is mainly about moving sprites, resizing them, rotating them, and all that. Not that you can’t use the framework in such cases, in fact the tutorial I wrote follows just such a case, but then the Controller side of things might get left out a bit. But you will see what I mean when we get to the actual tutorial.
Developing games with PureMVC might be weird, but then again it depends on the type of game. The Event model of the framework can fit very nicely with most types of games I’ve written, but the main advantages of the framework, by far, are: encapsulation and the management of user interface. Plus using MVC in everything you do will never hurt anybody.
I wanted with this tutorial to use PureMVC in this “interface manager” capacity, which is the one I use the most, unless I’m working on a more traditional type of application. The application I chose has buttons galore, at least three well defined sections, a bunch of states, manipulation and control of loaded data… and yet, the main point of the application is the manipulation of display objects.
This Post contains multiple pages:
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13

