First steps with PureMVC

After a first leap into design pat­terns dri­ven devel­op­ment with pixlib in AS2, fol­lowed later by an imple­men­ta­tion of Cairn­gorm, I decided to look for AS3 frame­works so I browsed the web and found this arti­cle talk­ing about a so-called PureMVC. I dis­liked the name at first (as if it mat­ters !), not to men­tion the arti­cle wasn’t prais­ing the frame­work at all. It made me curi­ous. I had to try it.

I took a look at the puremvc’s dia­gram and won­dered if I had missed some­thing essen­tial in my learn­ing of design pat­terns since I had never thought this far seen such an imple­men­ta­tion of MVC. I got the big pic­ture thanks to the doc­u­men­ta­tion and sam­ples on puremvc.org. I really appre­ci­ated the note­wor­thy efforts put in doc­u­men­ta­tion. The best prac­tices doc­u­ment is maybe one of the most use­ful doc­u­ments that answered (some of) my many ques­tions as every­thing was hazy in the begin­ning. Also, I have come across 10 tips for work­ing with PureMVC which is very useful.

For a time, it was good. Prob­lems appeared later on.

Abstrac­tion

This frame­work moti­vates me because it helps (forces) think­ing a level above in terms of abstrac­tion. Notwith­stand­ing this, it is still cloudy in my mind. I often have found myself won­der­ing what to do. For exam­ple let’s say I have a sec­tion of a web­site, Sec­tion­Medi­a­tor, that wants to pop­u­late its view with a list of but­tons whose data is loaded into Sec­tion­Re­mot­ing­Proxy. Let’s sup­pose all the classes I talk about below are reg­is­tered to the Appli­ca­tion­Fa­cade. My options :

  1. Send­ing a Noti­fi­ca­tion (with­out body) that the Sec­tion­Medi­a­tor lis­tens to, then retrieves the Sec­tion­Re­mot­ing­Proxy and gets the data it needs from the proxy by access­ing it directly
  2. Send­ing a Noti­fi­ca­tion, whose body is an Array of Item­DataVO (vari­able object), that the Sec­tion­Medi­a­tor lis­tens to, then use the array of vari­able objects to pop­u­late its viewComponent
  3. Send­ing a Noti­fi­ca­tion that will trig­ger a Com­mand which will retrieve both the Sec­tion­Medi­a­tor and Sec­tion­Re­mot­ing­Proxy instances so as to get the data of the lat­ter to trans­mit it to a method of the for­mer. Basi­cally, the com­mand does the job of updat­ing the SectionMediator’s viewComponent.
  4. Mix­ing options 2 and 3 : send a Noti­fi­ca­tion whose body is the VO that will trig­ger a Com­mand that needs only to retrieve the Sec­tion­Medi­a­tor and feed it the vari­able object from the Notification’s body.

Option 3 aug­ments loose cou­pling but is that really the best choice ? I read that Com­mands should be used as much as pos­si­ble and a Com­mand should know the least pos­si­ble the classes it’s using. So Option 4 might as well be my choice. But wait ! It’s actu­ally a com­pli­ca­tion of Option 2…which in turn is a com­pli­ca­tion of Option 1. Am I back to the begin­ning ? It may be so.

I still don’t know what is my choice. I’ll exper­i­ment some more and see what happens.


About this entry