Testing the PureMVC framework

Flash & Flex Friday, March 6th, 2009 @ 11:36 | Follow comments

Objective

Testing the PureMVC framework.

Evaluation

I decided to test using the PureMVC framework in a small application in order to find its pros and cons.

As I had tested setting up the framework once before (in another project), it wasn’t really a big deal installing it and creating my first classes. Also, after having spent a few hours reading the PureMVC documentation and best practices, I already had knowledge on how the system worked.

Result

After completing the application, I’ve found both pros and cons with the implementation of PureMVC.
(Please note that I haven’t taken other pros/cons to consideration here, such as how often the framework is updated, community size etc.)

Pros

  • A clear structure for Models, Views and Controllers – the roles of each part is quite easy to understand and make use of.
  • Good use of Controller part of MVC, which usually is difficult to put in the AS equation. In PureMVC, the Controller is a “Command” instructing the application on what to do next (i.e. to register Proxies/Mediators).
  • Good and clear separation of “true” View and Model via Proxy and Mediator – makes it easier to let the View actually “be a View” and Model “be a Model”. The View component (i.e. an actual MovieClip) is manipulated through the Mediator and the Model (i.e. a data object, such as a Player) is manipulated through a Proxy. This ensures that no logic is misplaced in the View component.
  • Nice being able to access Proxies, Mediators etc through the ApplicationFacade from wherever. Allows for Commands to be quite complicated if needed.

Cons

  • All Mediators, Proxies and Commands are registered using a unique key. Hence, there are some difficulties keeping track of Mediators/Views (“M-V”) that are unique for the Proxy’s data object, i.e. the M-V of a certain “Player” with a certain “id”. Perhaps M-V:s should only be implemented for functionality that will only require a single instance of its type?
  • Could be troublesome to keep track of the dependencies etc in the notification system, although the references can quite easily be searched using an IDE. This is probably an issue no matter which system being used.

Other observations (not necessarily to be considered as either pros or cons)’

  • The PureMVC “pattern” needs to be implemented all the way, meaning that the view (component) cannot contain any functionality to affect the world outside of it. A mediator’s “view component” must be completely isolated.
  • Setting up a new class requires some manual labor (as some classes needs to be extended/interfaces implemented), i.e. specifying which events to listen to and how it affects the class

What do I need to know to get started?

It takes a little effort to learn the system and understand what its parts do; i.e. what a Mediator is and how it correlates to the actual View. But once you understand the system, it’s really easy to create new classes for your application.

A few vital things that need to be understood before using PureMVC (I’ll try to sum it up, but the official docs are recommended):

  • What are Notifications? All Mediators, Proxies and Commands listen to notifications specified by the user. If a certain Mediator should display a message at a certain time, it will listen for a notification of that type.
  • What the Mediator is and why it’s being used: it’s basically a layer to the actual View (MovieClip), handling all functionality related to the other parts of the application (i.e. outside of the View)
  • What the Proxy is and why it’s being used: works in the same way as a Mediator, but in a more simpler way. Manipulates the “true” model object, which could be a domain object such as a “Player” or “Table” in a card game application.
  • Where is the Controller? The controller is implemented as a Command, meaning that it’s invoked when a certain notification is sent. Once invoked, it has no function until the notification is sent again.

Conclusion

In my point of view, PureMVC is a good framework to use for MVC applications. It can get a bit complex with boilerplate code, though.

References

Share article with others:

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Buzz

Leave a Reply