Space of Flex/AIR technologies

Beyond Plain Old Html Objects

My approach to MVP pattern with Swiz Framework

with 4 comments

Recently I noticed that MVP (Model View Presenter) pattern especially using Swiz Framework is becoming very popular. That is why I decided to port one of my old examples to checkout this approach. It is a simple Flex based notes editor, really really trivial one. As an inspiration and some guides I used one of Ben Clinkinbeard blog posts and also Soenke Rohde blog post. With my approach I introduce assumption that all/most PresentationModel classes extend AbstractPresentationModel class that also extends AbstractController from Swiz package. My abstract class adds dispatcher property that returns reference to CentralDispatcher (I guess this could be also a nice addition to Swiz itself). The assumption here is that communication between different PresentationModel classes is done only through events. Of course PresentationModel has direct access to views and model as with standard MVP, additionally I threat service delegates also as part of model. I guess this could be also called MVPS pattern ;)

Working application is here and application source code here.

I’m waiting for your comments, especially about approach to currentState switching in ApplicationPresentationModel.as and assumptions like event based communication between PresentationModel classes.

Here is just an overview diagram of the architecture, it doesn’t represent all dependencies between application components.

MVP Diagram

Written by Piotr Walczyszyn

September 1st, 2009 at 3:41 pm

Posted in Examples

Tagged with

4 Responses to 'My approach to MVP pattern with Swiz Framework'

Subscribe to comments with RSS or TrackBack to 'My approach to MVP pattern with Swiz Framework'.

  1. Very nice example. I’ll try this pattern on my app.

    Great post!

    Maxmiliano

    2 Sep 09 at 4:40 pm

  2. What if I had a TabNavigator in my ApplicationView.mxml and I wanted to add other views on each tab?

    Which class should dispatch the event to add this views? Is it possible do Mediate it on the ApplicationView.mxml?

    Maxmiliano

    8 Sep 09 at 2:10 pm

  3. Awesome post. Does anyone know if it is OK to add style names to presentation model classes?

    For example,

    public var price:Number;
    public var priceStyleName:String;
    public var priceOverStyleName:String;
    public var titleStyleName:String;

    Mike Hemelberg

    21 Jul 10 at 6:17 pm

  4. Sure you can, that what PresentationModel is for.

    Piotr Walczyszyn

    21 Jul 10 at 8:43 pm

Leave a Reply

Switch to our mobile site