First steps with PureMVC
After a first leap into design patterns driven development with pixlib in AS2, followed later by an implementation of Cairngorm, I decided to look for AS3 frameworks so I browsed the web and found this article talking about a so-called PureMVC. I disliked the name at first (as if it matters !), not to mention the article wasn’t praising the framework at all. It made me curious. I had to try it.
I took a look at the puremvc’s diagram and wondered if I had missed something essential in my learning of design patterns since I had never thought this far seen such an implementation of MVC. I got the big picture thanks to the documentation and samples on puremvc.org. I really appreciated the noteworthy efforts put in documentation. The best practices document is maybe one of the most useful documents that answered (some of) my many questions as everything was hazy in the beginning. Also, I have come across 10 tips for working with PureMVC which is very useful.
For a time, it was good. Problems appeared later on.
Abstraction
This framework motivates me because it helps (forces) thinking a level above in terms of abstraction. Notwithstanding this, it is still cloudy in my mind. I often have found myself wondering what to do. For example let’s say I have a section of a website, SectionMediator, that wants to populate its view with a list of buttons whose data is loaded into SectionRemotingProxy. Let’s suppose all the classes I talk about below are registered to the ApplicationFacade. My options :
- Sending a Notification (without body) that the SectionMediator listens to, then retrieves the SectionRemotingProxy and gets the data it needs from the proxy by accessing it directly
- Sending a Notification, whose body is an Array of ItemDataVO (variable object), that the SectionMediator listens to, then use the array of variable objects to populate its viewComponent
- Sending a Notification that will trigger a Command which will retrieve both the SectionMediator and SectionRemotingProxy instances so as to get the data of the latter to transmit it to a method of the former. Basically, the command does the job of updating the SectionMediator’s viewComponent.
- Mixing options 2 and 3 : send a Notification whose body is the VO that will trigger a Command that needs only to retrieve the SectionMediator and feed it the variable object from the Notification’s body.
Option 3 augments loose coupling but is that really the best choice ? I read that Commands should be used as much as possible and a Command should know the least possible the classes it’s using. So Option 4 might as well be my choice. But wait ! It’s actually a complication of Option 2…which in turn is a complication of Option 1. Am I back to the beginning ? It may be so.
I still don’t know what is my choice. I’ll experiment some more and see what happens.
About this entry
You’re currently reading “First steps with PureMVC,” an entry on Théâtre magique
- Published:
- 03.22.08 / 10am
- Category:
- Flash/Flex
No comments
Jump to comment form | comments rss [?] | trackback uri [?]