Friday, January 16, 2009

PureMVC and Guidelines

PureMVC is a framework which helps the Flex programmers to create applications in the MVC architecture. It helps the programmers to develop loosely coupled components. It helps to create the resusable codes. Very easy to understand and maintain than other frameworks. Forces the singleton pattern.

We can divide the pureMVC as:

  • Facade & Core
  • Controller & Commands
  • Model & Proxies
  • View & Mediators
  • Observers & Notifications

Steps to follow in PureMVC

1. Main application should call the facade.startup(this). Here facade is the singletone instance of ApplicationFacade class.

2. ApplicationFacade

  • Singleton class.
  • It extedns the org.puremvc.as3.patterns.facade.Facade.
  • It implements org.puremvc.as3.interfaces.IFacade .
  • Should override the initializeController() method.
  • It defines static constants for Notification names.
  • Initializes the Commands used to access and notify the Commands, Mediators and Proxies.

3. MacroCommand(s)

  • It extends the org.puremvc.as3.patterns.command.MacroCommand.
  • It implements the org.puremvc.as3.interfaces.ICommand.
  • Should override the initializeMacroCommand() method.
  • Executes the SimpleCommands and MacroCommands.
  • User can registerand retrieve the Mediators and Proxies.

4. SimpleCommand(s)

  • It extends the org.puremvc.as3.patterns.command.SimpleCommand.
  • It implements org.puremvc.as3.interfaces.ICommand.
  • Should override the execute( note:INotification ) method.
  • User can register and retrieve the Mediators and proxies.

5. Mediator(s)

  • It extends the org.puremvc.as3.patterns.mediator.Mediator.
  • It implements the org.puremvc.as3.interfaces.IMediator.
  • Should override the listNotificationInterests() and handleNotification( note:INotification ) methods to listen to the notifications.
  • Registers the mediators and proxies.
  • User can retrieve the Mediators and proxies.
  • User can register the notifications.
  • Listens for the notifications from other Mediators, Proxies and commands.
  • Listens for the events from the component.
  • Sends the notifications to other mediators.

6. Proxy(ies)

  • It extends org.puremvc.as3.patterns.proxy.Proxy.
  • It implents the interface org.puremvc.as3.interfaces.IProxy.
  • User can send the notifications.
  • Used to access the Delegates and datas.

7. Component(s)

  • Views of our application.
  • Every component should have its own Mediator. One Mediator per Component.
  • Dispatches the event. So the mediator can listen for that events.

Observers

PureMVC applications may run in environments without access to Flash’s Event and EventDispatcher classes, so the framework implements an Observer notification scheme for communication between the Core MVC actors and other parts of the system in a loosely-coupled way. No need to create instance for the Observers and notificatios. These are inbuilt things in the pureMVC.

Notifications
PureMVC implements the Observer pattern so that the Core actors and their collaborators can communicate in a loosely-coupled way, and without platform dependency.

Not simply a replacement for Events, Notifications operate in a fundamentally different way, and work synergistically with Events to produce extremely reusable View Components that need not even know that they are coupled to a PureMVC system at all if engineered properly.

Events are dispatched from Flash display objects that implement the IEventDispatcher interface. The Event is ‘bubbled’ up the display hierarchy, allowing the parent object to handle the Event, or the parent’s parent, etc.

Notifications are sent by the Facade and Proxies; listened for and sent by Mediators; mapped to and sent by Commands. It is a publish/subscribe mechanism whereby many Observers may receive and act upon the same Notification.

WorkFlow of the PureMVC framework

  • MainApplication should startup the pureMVC framework by calling the ApplicationFacade(Facade)’s startup method.
  • ApplicationFacade Registers the Commands,Mediators and Proxies.
  • User can retrieve the Mediators and Proxies in the ApplicationFacade.
  • Two commands are there: MacroCommand and SimpleCommand.
  • MacroCommand registers other commands, Mediators and Proxies.
  • SimpleCommand registers the Mediators and Proxies.
  • Both the Macro and Simple Commands can be used to retrieve the Mediators and Proxies.
  • User can send notifications from both the Macro and Simple commands.
  • Mediators registers the component with the PureMVC.
  • Mediators will listen for the events and notifications.
  • Mediators will listen for the events dispatched from the Components.
  • Mediators will listen for the notifications sent from the other Mediators, Proxies and Commands.
Courtesy:ponbharathi

No comments: