Category Archives: puremvc

These are for article about puremvc

Actionscript 3 and PureMVC Introduction

I have run into some questions about using PureMVC. I thought I would start writing some information to help out. In this first section, I will go over the sections of PureMVC. Take note, I will be using ActionScript 3, which I will only briefly talk about.

What is PureMVC – It’s an architectural framework for model view controller. In English, I just said PureMVC is a library that will let write code where the graphical components and the computational components of the software interact through a middle layer so they don’t know anything about each other. It is a full library giving you all the classes you need for most scenarios to implement MVC. It contains all of the middle layers for you to plug in your models, view, controllers, and entities. MVC is way to build software where parts of your software don’t know how other parts of your software work. This means when you change on part of your software, you won’t have to change all the things which work the changed part. Also if a part of your software breaks, that broken part is isolated because nothing cares about the detail of how that piece of software works.

MVC is broken into four parts:
Models – This is the part of the architecture which does the computations. These classes would know how to add complex numbers together, but will not know how to display them. Nor would they be able to get them from the user.
Views –These are graphical elements that are shown are the screen. They know how they are shown and what they do, but not necessarily how they do it.
Controllers-This part controls the state and interaction between the models and views. The controllers would know what the view needs to do when the user requests to multiply two complex numbers together on a view. It would ship those numbers to the model and then return that result to the view.
Common- These are your shared components that are used by every layers. Entities are a perfect example of a common component. Suppose a complex number class is displayed by the view and calculated by the model. Instead of needing to return different values (the regular part and the imaginary part), you can make a class that contains both. This class would be an example of an entity. This entity can be used by the view when determining how to show the complex number and the model for computing math.

Implementing this in PureMVC is not the easiest thing. PureMVC focuses on proxies, commands, and mediators. Sadly these components do not have a 1-1 relationship to models, views, and controllers. You would still create your views normally in fact. You mediators would be your controllers. Nothing directly talks to your models; instead they use proxies to retrieve information from models. Proxies are an abstraction from models, in case your models are external entities. Communications between everything are done through commands. Commands are like events as everything on the framework listens for them, the difference is they don’t have to know what is throwing the event.

In the next article I will go into actually creating views, entities, proxies, models, commands, mediators, and yes, you will need a main class to start everything up.

Fun fact – You do not inherit your models, views, and controllers from the classes in PureMVC. Find out why later 😉