My approach to MVP pattern with Swiz Framework
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.



Very nice example. I’ll try this pattern on my app.
Great post!
Maxmiliano
2 Sep 09 at 4:40 pm
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
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
Sure you can, that what PresentationModel is for.
Piotr Walczyszyn
21 Jul 10 at 8:43 pm
You Wowed me! Piotr
Thanks a million this is the best example I have seen.
Not to complicated and bloated to understand. Now to answer Mike Hemelberg question The PresentationModel is very similar logic to sparkSkin styles, when sparkSkin is instantiated and given an name then you can have as many style directives for as many viewStates and you would call it like any other object so you could keep all you constant Vars like
public Static Const PRICE_STYLE_NAME:String = priceStyleName; and so on
TJ
22 Sep 10 at 8:06 am
@TJ thank you!
Piotr Walczyszyn
22 Sep 10 at 9:00 am
Hi, great work! I don’t get the view switching work. The currentView string is updated in my applicationModel, but I’don’t understand how the switching is performed. I would really appreciate your help! Thanks in advance.
Mirko
5 Jun 11 at 2:43 pm