Wednesday, September 28, 2011

Pure MVC framework...




Goal of this framework is to impose Model View Controller design pattern on application .
This framework is typically used with adobe flex.This is completely written in action script.

It uses singleton , facade , Observer and MVC design pattern in mixture .

Main components of it are

Core Actors - Model , View , Controller
Central Point to all actors - Facade

Facade (singleton - common gateway for notifications )
Facade is singleton class .This is instantiated from mxml after it has created all of its children components.
Every interaction with application goes through facade .
This class extends Facade class and implements IFacade.as

 ApplicationFacade.as:
package com.me.myapp
{
import org.puremvc.as3.interfaces.*;
import org.puremvc.as3..patterns.facade.*;
import com.me.myapp.view.*;
import com.me.myapp.model.*;
import com.me.myapp.controller.*;
// A concrete Facade for MyApp
public class ApplicationFacade extends Façade implements IFacade
{
// Define Notification name constants
public static const STARTUP:String = "startup";
public static const LOGIN:String = "login";
// Singleton ApplicationFacade Factory Method
public static function getInstance() : ApplicationFacade
{
if ( instance == null ) instance = new ApplicationFacade( );
return instance as ApplicationFacade;
}
// Register Commands with the Controller
override protected function initializeController( ) : void
{
super.initializeController();
registerCommand( STARTUP, StartupCommand );
registerCommand( LOGIN, LoginCommand );
registerCommand( LoginProxy.LOGIN_SUCCESS, GetPrefsCommand );
}
// Startup the PureMVC apparatus, passing in a reference to the application public function startup( app:MyApp ) : void
{
sendNotification( STARTUP, app );
}
}
}


 <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="façade.startup(this)”>
<mx:Script>
<![CDATA[
// Get the ApplicationFacade
import com.me.myapp.ApplicationFacade;
private var facade:ApplicationFacade = ApplicationFacade.getInstance();
]]>
</mx:Script>
<!—Rest of display hierarchy defined here -->
</mx:Application


Notifications -

Used for loose coupling .It is part of observer design pattern.They are like events .
Notifications can be sent by facade and proxies ; listened for and sent by mediators , mapped to send by commands.Many observers can receive same notification and can act on it .
Notification have , notification name , body(it may be any object of action script) , type .

Commands(controller - stateless, Extends Model and implements IModel.as) -
Mapping of command to notification is done in concrete facade exp may be - ApplicationFacade.as
Command is observer for notification for which it is registered.
After getting notification from mxml facade searches for registered command and invokes execute method of it .Commands are stateless means no static reference to them just created and destroyed when notification's work is completed.
They implement Icommand interface.

Mediators (Controller - stateless) -
Agent between view component and other core components .
It can send or receive notifications.
It handles events from view and notifications from rest of puremvc.
It takes name and view object as in constructor of its super class.So it is coupled with view components of flex like data grid.So you can modify view through mediator by accessing view objects.We can cast this view object to desired component like progress bar , grid etc and mutate it.

Proxie (Model - stateless)-
As direct java beans are not accessible in flex they have created surrogate objects in .as as data carriers .These are called as proxies.One can imagine that they are proxies for real java beans.
In proxie depending on your choice of webservice , SAOP, AMF messaging you can talk with real java objects on server .


Simple flow

mxml (Flex View ) ==> On complete create singleton facade ==> send some notification to facade on action ==> Facade looks for mediators , commands registered for that notification ==> registered commands execute method is called ==> command may call some methods of proxies which in turn talk with Java actual objects ==> proxy send response to mediator ==> mediator interpret it and modify view >> proper result is displayed in view or mxml.




References and downloads




Friday, September 9, 2011

Aspect Oriented Programming (AOP) and use in Spring

  1. Concept of AOP
  2. Why to use AOP
  3. How to use in Spring
  4. Simple example

Tuesday, September 6, 2011

Spring/BlazeDS integration

1. What is BlazeDS ?
2. Advantages of using BlazeDS for Spring /Flex
3. Simple Example .
4. Video from adobe

A good video for Flex/BlazeDS greenHorns