SlideShare a Scribd company logo
1 of 44
Flex London, Feb 2010



Application Frameworks
The Good, the Bad & the Ugly

          Richard Lord

         Technical Architect
             BrightTALK
         www.brighttalk.com
Application Frameworks

       Cairngorm
       PureMVC
         Mate
         Swiz
        Parsley
       RobotLegs
Coming Up
Model-View-Controller

Managing Dependencies

   Managing Events

 Presentation Patterns

What is Cairngorm 3?

Some measured opinion
Model-View-Controller

Model                View




        Controller
Managing Dependencies
                     Model
                                               View
         Model


Model
                                               View




                                               View




        Controller   Controller   Controller
Cairngorm uses global singletons
        Model Singleton
                                                    View
Model        Model        Model



                                                    View




                                                    View




           Controller     Controller   Controller
Cairngorm uses a Singleton

Model is a Singleton
  class ModelLocator implements IModelLocator {
    public static function getInstance():ModelLocator {
      ...
    }
    [Bindable]
    public var user:User;
  }


View / Controller access that Singleton
  var user:User = ModelLocator.getInstance().user;
PureMVC uses a registry
                   Model
                                                  View

        Model


Model
                                                  View
                            Model Registry




                                                  View




          Controller   Controller    Controller
Accessing the model in Pure MVC

Model is a registry of proxies
  class UserProxy extends Proxy implements IProxy {
    public function get user():User {
      ...
    }                                         Add object     to registry
  }

  facade.registerProxy( new UserProxy() );


View / Controller fetch proxies from the registry
  var userProxy:UserProxy = facade.retrieveProxy( "UserProxy" )
                                  as UserProxy;
  var user:User = userProxy.user;

                                             Fetch object from registry
Others use dependency injection
                   Model
                                                 View

        Model


Model                        Dependency          View
                              Injection
                              Container



                                                 View




          Controller   Controller   Controller
Accessing the model in Mate
Injection rules are defined in EventMaps
  <mx:Script>
   modelManager = new ModelManager();
   modelManager.user = new User();            The Model is one or
  </mx:Script>                                more regular objects

  <Injectors target="{ProfileView}">
    <PropertyInjector source="{ModelManager}" sourceKey="user"
       targetKey="user"/>
  </Injectors>
                                            Define injection rules

Properties are injected into the view
  public class ProfileView {
    public var user:User;                   This will be set by
    //...
  }
                                            the DI container
Accessing the model in Swiz

Injection rules are defined in BeanLoaders
  <BeanLoader>
   <User id="user"/>
  </BeanLoader>                            Regular object
                                          defined in MXML

BeanLoaders are instatiated in your application
  <SwizConfig beanLoaders="{[MyBeans]}">



Objects specify their requirements
  [Autowire]
  public var user:User;                      And injected into
                                              other objects
Accessing the model in RobotLegs

Injection rules are defined in a context
  class MyAppContext {
    override public function startup():void {
      injector.mapSingleton( User );
    }
                                                      Injection rules are
  }                                                 defined in the context

Context is instatiated in your application
  <MyAppContext contextView="{this}">


Objects specify their requirements
  [Inject]
  public var user:User;                         And injected into
                                                 other objects
Accessing the model in Parsley

Injection rules are defined in a configuration object
  <mx:Object>
   <User id="user"/>                      Model objects
  </mx:Object>                        are created in a config
                                              object

Configuration object is instatiated in your application
  <ContextBuilder config="{MyAppConfig}">



Objects specify their requirements
  [Inject]
  public var user:User;                   And injected into
                                           other objects
Managing Dependencies


        Singleton

         Registry

   Dependency Injection
Handling Events

Model                     View




            Controller
Event Bus
                              View     View   View




                          Event Bus




Controller   Controller   Controller
Using a single event dispatcher
                               View      View   View




                              Event
                            Dispatcher




 Controller   Controller   Controller
Using a single event dispatcher

View
  var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN);
  loginEvent.username = username.text;
  loginEvent.password = password.text;
  singleEventDispatcher.dispatchEvent( loginEvent );




Controller
  singleEventDispatcher.addEventListener( LoginEvent.LOGIN,
                               loginHandler )
View-Controller in Cairngorm
                                extends CairngormEvent
View
  var loginEvent:LoginEvent = new LoginEvent( LoginEvent.LOGIN );
  loginEvent.username = username.text;
  loginEvent.password = password.text;
  loginEvent.dispatchEvent();

Front Controller
  addCommand( LoginEvent.LOGIN, LoginCommand );

Command
  public class LoginCommand extends Command {
    public function execute( event:Event ):void {
      var loginEvent:LoginEvent = event as LoginEvent;
      ...
    }
  }
View-Controller in Pure MVC

View                                                  Notifications are
  var loginData:LoginData = new LoginData();            like Events
  loginData.username = username.text;
  loginData.password = password.text;
  sendNotification( NotificationNames.LOGIN, loginData );

Controller
  registerCommand( NotificationNames.LOGIN, LoginCommand );

Command
  public class LoginCommand extends SimpleCommand {
    public function execute( note:INotification ):void {
      var loginData: LoginData = note.getBody() as LoginData;
      ...
    }
  }
View-Controller in RobotLegs
View
 var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN);
 loginEvent.username = username.text;
 loginEvent.password = password.text;                 Reference to
 eventDispatcher.dispatchEvent( loginEvent );      central dispatcher   is
                                                         injected
Context
 commandMap.mapEvent( LoginCommand, LoginEvent.LOGIN );

Command
 public class LoginCommand extends Command {
  [Inject]
  public var event:LoginEvent;

     public function execute():void {
       ...
     }
 }
View-Controller in Parsley
                                                 Central dispatcher will
View                                              redispatch this event
 [Event(name="login",type="LoginEvent")]
 [ManagedEvents("login")]
 var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN);
 loginEvent.username = username.text;
 loginEvent.password = password.text;
 dispatchEvent( loginEvent );

Configuration
 <DynamicCommand type="" selector="login"/>

Command
  public class LoginCommand {
    public function execute( event:LoginEvent ):void {
      ...
    }
  }
View-Controller in Parsley II
                                                Central dispatcher will
View                                             redispatch this event
  [Event(name="login",type="LoginEvent")]
  [ManagedEvents("login")]
  var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN);
  loginEvent.username = username.text;
  loginEvent.password = password.text;
  dispatchEvent( loginEvent );

                                                     The method
Controller                                         handles this event

  [MessageHandler(selector="login")]
  public function loginHandler( event:LoginEvent ):void {
    ...
  }
Using the display list
      Add listeners here
                                            System Manager



                            Application                          Pop-up



Display Object             Display Object               Module



Display Object             Display Object            Display Object



Display Object             Display Object            Display Object
View-Controller in Swiz

View
  var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN, true);
  loginEvent.username = username.text;
  loginEvent.password = password.text;
  dispatchEvent( loginEvent );
                                                   Bubbling
                                                    Event


Controller
  [Mediate(event="LoginEvent.LOGIN")]
  public function loginHandler( event:LoginEvent ):void {
    ...
  }
View-Controller in Mate

View
 var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN, true);
 loginEvent.username = username.text;
 loginEvent.password = password.text;
 dispatchEvent( loginEvent );
                                                Bubbling
                                                 Event


Event Map
 <EventHandlers type="{LoginEvent.LOGIN}">
  ...
 </EventHandlers>
Mate has local event maps
   Main event map
                                     System Manager



                     Application                          Pop-up



Display Object      Display Object               Module

                                                                   Local event map

Display Object      Display Object            Display Object



Display Object      Display Object            Display Object
Event Bus


    Single Event Dispatcher
(may have multiple with access method)



           Display List
  (may use localised event handling)
Presentation Patterns

                        View     View
Model
                        logic   display




           Controller
Code Behind
View Display
  <LoginCanvas>
   <VBox>
    <TextInput id="username"/>
    <TextInput id="password"/>
    <Button click="sendLogin( username.text, password.text )"/>
   </VBox>
  </LoginCanvas>


View Logic
  class LoginCanvas extends Canvas {
    public function sendLogin( username, password ) {
      ....
    }
  }
Presentation Model
View Display
  <Canvas>
   <LoginPresentationModel id="pm"/>
   <VBox>
    <TextInput id="username"/>
    <TextInput id="password"/>
    <Button click="pm.sendLogin( username.text, password.text )"/>
   </VBox>
  </Canvas>


View Logic
  class LoginPresentationModel {
    public function sendLogin( username, password ) {
      ....
    }
  }
Supervising Controller
View Display
  <Canvas>
   <VBox>
    <TextInput id="username"/>
    <TextInput id="password"/>
    <Button click="dispatchEvent( new LoginEvent(
        LoginEvent.LOGIN, username.text, password.text ) )"/>
   </VBox>
  </Canvas>


View Logic
  class LoginController {
    public function LoginController( display:LoginDisplay ) {
      display.addEventListener( LoginEvent.LOGIN, sendLogin );
    }
    private function sendLogin( event:LoginEvent ) {
      ....
    }
  }
Passive View
View Display
  <Canvas>
   <VBox>
    <TextInput id="username"/>
    <TextInput id="password"/>
    <Button id="loginBtn"/>
   </VBox>
  </Canvas>


View Logic
  class LoginController {
    public function LoginController( display:LoginDisplay ) {
      display.loginBtn.addEventListener( MouseEvent.click, sendLogin );
    }
    private function sendLogin( event:MouseEvent ) {
      ....
    }
  }
Presentation Patterns


      Code Behind

   Presentation Model

  Supervising Controller

       Passive View        PureMVC &
                            Robotlegs
                            Mediators
Setting up the mediator
Pure MVC
 facade.registerMediator( new LoginMediator( loginView ) );


                   Logic                                      Display

RobotLegs
 mediatorMap.mapView( LoginView, LoginMediator );


       Display                                     Logic
So what is Cairngorm 3?




 Cairngorm 3 == Parsley 2.2
Summary and Opinion

      Cairngorm
      PureMVC
        Mate
        Swiz
       Parsley
      RobotLegs
Framework or Toolkit

MVC Framework      Toolkit

  Cairngorm         Swiz
  PureMVC          Parsley
    Mate          RobotLegs
Platforms


Flash & Flex     Flex only

PureMVC         Cairngorm
 Parsley          Mate
RobotLegs          Swiz
Modular features

        Yes                  No

PureMVC (multicore)       Cairngorm
       Mate           PureMVC (standard)
      Parsley
    RobotLegs
       Swiz
Community involvement

Corporate                            Community

Cairngorm                                Robotlegs
            Parsley               Swiz
                 Mate
                        PureMVC
History and evolution
Generation 1.0   Cairngorm   Out of date


                 PureMVC
Generation 1.5                 Mature
                   Mate

                   Swiz
Generation 2.0    Parsley    Cutting edge

                 RobotLegs
This is me



  www.richardlord.net

twitter.com/Richard_Lord

More Related Content

What's hot

Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
Mathias Seguy
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice Presentation
Dmitry Buzdin
 
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScriptWhy SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScript
martinlippert
 
Laporan multi client
Laporan multi clientLaporan multi client
Laporan multi client
ichsanbarokah
 

What's hot (20)

Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CN
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
 
Jug Guice Presentation
Jug Guice PresentationJug Guice Presentation
Jug Guice Presentation
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
iOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + GherkiniOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + Gherkin
 
Why SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScriptWhy SOLID matters - even for JavaScript
Why SOLID matters - even for JavaScript
 
Laporan multi client
Laporan multi clientLaporan multi client
Laporan multi client
 
Android 3
Android 3Android 3
Android 3
 
iOS Contact List Application Tutorial
iOS Contact List Application TutorialiOS Contact List Application Tutorial
iOS Contact List Application Tutorial
 
Google Guice
Google GuiceGoogle Guice
Google Guice
 
Client-side JavaScript
Client-side JavaScriptClient-side JavaScript
Client-side JavaScript
 
French kit2019
French kit2019French kit2019
French kit2019
 
softshake 2014 - Java EE
softshake 2014 - Java EEsoftshake 2014 - Java EE
softshake 2014 - Java EE
 
Unit Test 最後一哩路
Unit Test 最後一哩路Unit Test 最後一哩路
Unit Test 最後一哩路
 
Android UI Fundamentals part 1
Android UI Fundamentals part 1Android UI Fundamentals part 1
Android UI Fundamentals part 1
 
Deployment
DeploymentDeployment
Deployment
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
iOS UI Testing in Xcode
iOS UI Testing in XcodeiOS UI Testing in Xcode
iOS UI Testing in Xcode
 
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group Cut your Dependencies with Dependency Injection for East Bay.NET User Group
Cut your Dependencies with Dependency Injection for East Bay.NET User Group
 

Similar to Application Frameworks - The Good, The Bad & The Ugly

Displaying additional image types in XMetaL
Displaying additional image types in XMetaLDisplaying additional image types in XMetaL
Displaying additional image types in XMetaL
XMetaL
 
#win8aca : How and when metro style apps run
#win8aca : How and when metro style apps run#win8aca : How and when metro style apps run
#win8aca : How and when metro style apps run
Frederik De Bruyne
 
Controllers & actions
Controllers & actionsControllers & actions
Controllers & actions
Eyal Vardi
 
Integrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight ApplicationsIntegrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight Applications
Dan Wahlin
 
Parsley & Flex
Parsley & FlexParsley & Flex
Parsley & Flex
prideconan
 
iPhoneOS3.1でのカメラAPIについて
iPhoneOS3.1でのカメラAPIについてiPhoneOS3.1でのカメラAPIについて
iPhoneOS3.1でのカメラAPIについて
Kyosuke Takayama
 

Similar to Application Frameworks - The Good, The Bad & The Ugly (20)

Architecting ActionScript 3 applications using PureMVC
Architecting ActionScript 3 applications using PureMVCArchitecting ActionScript 3 applications using PureMVC
Architecting ActionScript 3 applications using PureMVC
 
Displaying additional image types in XMetaL
Displaying additional image types in XMetaLDisplaying additional image types in XMetaL
Displaying additional image types in XMetaL
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
Riacon swiz
Riacon swizRiacon swiz
Riacon swiz
 
#win8aca : How and when metro style apps run
#win8aca : How and when metro style apps run#win8aca : How and when metro style apps run
#win8aca : How and when metro style apps run
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAX
 
Controllers & actions
Controllers & actionsControllers & actions
Controllers & actions
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
Integrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight ApplicationsIntegrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight Applications
 
Command Query Responsibility Segregation and Event Sourcing
Command Query Responsibility Segregation and Event SourcingCommand Query Responsibility Segregation and Event Sourcing
Command Query Responsibility Segregation and Event Sourcing
 
Parsley & Flex
Parsley & FlexParsley & Flex
Parsley & Flex
 
Asp.Net Control Architecture
Asp.Net Control ArchitectureAsp.Net Control Architecture
Asp.Net Control Architecture
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
From mvc to viper
From mvc to viperFrom mvc to viper
From mvc to viper
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4
 
Dependency Injection for Android
Dependency Injection for AndroidDependency Injection for Android
Dependency Injection for Android
 
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
 
Provider vs BLoC vs Redux
Provider vs BLoC vs ReduxProvider vs BLoC vs Redux
Provider vs BLoC vs Redux
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
iPhoneOS3.1でのカメラAPIについて
iPhoneOS3.1でのカメラAPIについてiPhoneOS3.1でのカメラAPIについて
iPhoneOS3.1でのカメラAPIについて
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Application Frameworks - The Good, The Bad & The Ugly

  • 1. Flex London, Feb 2010 Application Frameworks The Good, the Bad & the Ugly Richard Lord Technical Architect BrightTALK www.brighttalk.com
  • 2. Application Frameworks Cairngorm PureMVC Mate Swiz Parsley RobotLegs
  • 3. Coming Up Model-View-Controller Managing Dependencies Managing Events Presentation Patterns What is Cairngorm 3? Some measured opinion
  • 4. Model-View-Controller Model View Controller
  • 5. Managing Dependencies Model View Model Model View View Controller Controller Controller
  • 6. Cairngorm uses global singletons Model Singleton View Model Model Model View View Controller Controller Controller
  • 7. Cairngorm uses a Singleton Model is a Singleton class ModelLocator implements IModelLocator { public static function getInstance():ModelLocator { ... } [Bindable] public var user:User; } View / Controller access that Singleton var user:User = ModelLocator.getInstance().user;
  • 8. PureMVC uses a registry Model View Model Model View Model Registry View Controller Controller Controller
  • 9. Accessing the model in Pure MVC Model is a registry of proxies class UserProxy extends Proxy implements IProxy { public function get user():User { ... } Add object to registry } facade.registerProxy( new UserProxy() ); View / Controller fetch proxies from the registry var userProxy:UserProxy = facade.retrieveProxy( "UserProxy" ) as UserProxy; var user:User = userProxy.user; Fetch object from registry
  • 10. Others use dependency injection Model View Model Model Dependency View Injection Container View Controller Controller Controller
  • 11. Accessing the model in Mate Injection rules are defined in EventMaps <mx:Script> modelManager = new ModelManager(); modelManager.user = new User(); The Model is one or </mx:Script> more regular objects <Injectors target="{ProfileView}"> <PropertyInjector source="{ModelManager}" sourceKey="user" targetKey="user"/> </Injectors> Define injection rules Properties are injected into the view public class ProfileView { public var user:User; This will be set by //... } the DI container
  • 12. Accessing the model in Swiz Injection rules are defined in BeanLoaders <BeanLoader> <User id="user"/> </BeanLoader> Regular object defined in MXML BeanLoaders are instatiated in your application <SwizConfig beanLoaders="{[MyBeans]}"> Objects specify their requirements [Autowire] public var user:User; And injected into other objects
  • 13. Accessing the model in RobotLegs Injection rules are defined in a context class MyAppContext { override public function startup():void { injector.mapSingleton( User ); } Injection rules are } defined in the context Context is instatiated in your application <MyAppContext contextView="{this}"> Objects specify their requirements [Inject] public var user:User; And injected into other objects
  • 14. Accessing the model in Parsley Injection rules are defined in a configuration object <mx:Object> <User id="user"/> Model objects </mx:Object> are created in a config object Configuration object is instatiated in your application <ContextBuilder config="{MyAppConfig}"> Objects specify their requirements [Inject] public var user:User; And injected into other objects
  • 15. Managing Dependencies Singleton Registry Dependency Injection
  • 16. Handling Events Model View Controller
  • 17. Event Bus View View View Event Bus Controller Controller Controller
  • 18. Using a single event dispatcher View View View Event Dispatcher Controller Controller Controller
  • 19. Using a single event dispatcher View var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN); loginEvent.username = username.text; loginEvent.password = password.text; singleEventDispatcher.dispatchEvent( loginEvent ); Controller singleEventDispatcher.addEventListener( LoginEvent.LOGIN, loginHandler )
  • 20. View-Controller in Cairngorm extends CairngormEvent View var loginEvent:LoginEvent = new LoginEvent( LoginEvent.LOGIN ); loginEvent.username = username.text; loginEvent.password = password.text; loginEvent.dispatchEvent(); Front Controller addCommand( LoginEvent.LOGIN, LoginCommand ); Command public class LoginCommand extends Command { public function execute( event:Event ):void { var loginEvent:LoginEvent = event as LoginEvent; ... } }
  • 21. View-Controller in Pure MVC View Notifications are var loginData:LoginData = new LoginData(); like Events loginData.username = username.text; loginData.password = password.text; sendNotification( NotificationNames.LOGIN, loginData ); Controller registerCommand( NotificationNames.LOGIN, LoginCommand ); Command public class LoginCommand extends SimpleCommand { public function execute( note:INotification ):void { var loginData: LoginData = note.getBody() as LoginData; ... } }
  • 22. View-Controller in RobotLegs View var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN); loginEvent.username = username.text; loginEvent.password = password.text; Reference to eventDispatcher.dispatchEvent( loginEvent ); central dispatcher is injected Context commandMap.mapEvent( LoginCommand, LoginEvent.LOGIN ); Command public class LoginCommand extends Command { [Inject] public var event:LoginEvent; public function execute():void { ... } }
  • 23. View-Controller in Parsley Central dispatcher will View redispatch this event [Event(name="login",type="LoginEvent")] [ManagedEvents("login")] var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN); loginEvent.username = username.text; loginEvent.password = password.text; dispatchEvent( loginEvent ); Configuration <DynamicCommand type="" selector="login"/> Command public class LoginCommand { public function execute( event:LoginEvent ):void { ... } }
  • 24. View-Controller in Parsley II Central dispatcher will View redispatch this event [Event(name="login",type="LoginEvent")] [ManagedEvents("login")] var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN); loginEvent.username = username.text; loginEvent.password = password.text; dispatchEvent( loginEvent ); The method Controller handles this event [MessageHandler(selector="login")] public function loginHandler( event:LoginEvent ):void { ... }
  • 25. Using the display list Add listeners here System Manager Application Pop-up Display Object Display Object Module Display Object Display Object Display Object Display Object Display Object Display Object
  • 26. View-Controller in Swiz View var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN, true); loginEvent.username = username.text; loginEvent.password = password.text; dispatchEvent( loginEvent ); Bubbling Event Controller [Mediate(event="LoginEvent.LOGIN")] public function loginHandler( event:LoginEvent ):void { ... }
  • 27. View-Controller in Mate View var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN, true); loginEvent.username = username.text; loginEvent.password = password.text; dispatchEvent( loginEvent ); Bubbling Event Event Map <EventHandlers type="{LoginEvent.LOGIN}"> ... </EventHandlers>
  • 28. Mate has local event maps Main event map System Manager Application Pop-up Display Object Display Object Module Local event map Display Object Display Object Display Object Display Object Display Object Display Object
  • 29. Event Bus Single Event Dispatcher (may have multiple with access method) Display List (may use localised event handling)
  • 30. Presentation Patterns View View Model logic display Controller
  • 31. Code Behind View Display <LoginCanvas> <VBox> <TextInput id="username"/> <TextInput id="password"/> <Button click="sendLogin( username.text, password.text )"/> </VBox> </LoginCanvas> View Logic class LoginCanvas extends Canvas { public function sendLogin( username, password ) { .... } }
  • 32. Presentation Model View Display <Canvas> <LoginPresentationModel id="pm"/> <VBox> <TextInput id="username"/> <TextInput id="password"/> <Button click="pm.sendLogin( username.text, password.text )"/> </VBox> </Canvas> View Logic class LoginPresentationModel { public function sendLogin( username, password ) { .... } }
  • 33. Supervising Controller View Display <Canvas> <VBox> <TextInput id="username"/> <TextInput id="password"/> <Button click="dispatchEvent( new LoginEvent( LoginEvent.LOGIN, username.text, password.text ) )"/> </VBox> </Canvas> View Logic class LoginController { public function LoginController( display:LoginDisplay ) { display.addEventListener( LoginEvent.LOGIN, sendLogin ); } private function sendLogin( event:LoginEvent ) { .... } }
  • 34. Passive View View Display <Canvas> <VBox> <TextInput id="username"/> <TextInput id="password"/> <Button id="loginBtn"/> </VBox> </Canvas> View Logic class LoginController { public function LoginController( display:LoginDisplay ) { display.loginBtn.addEventListener( MouseEvent.click, sendLogin ); } private function sendLogin( event:MouseEvent ) { .... } }
  • 35. Presentation Patterns Code Behind Presentation Model Supervising Controller Passive View PureMVC & Robotlegs Mediators
  • 36. Setting up the mediator Pure MVC facade.registerMediator( new LoginMediator( loginView ) ); Logic Display RobotLegs mediatorMap.mapView( LoginView, LoginMediator ); Display Logic
  • 37. So what is Cairngorm 3? Cairngorm 3 == Parsley 2.2
  • 38. Summary and Opinion Cairngorm PureMVC Mate Swiz Parsley RobotLegs
  • 39. Framework or Toolkit MVC Framework Toolkit Cairngorm Swiz PureMVC Parsley Mate RobotLegs
  • 40. Platforms Flash & Flex Flex only PureMVC Cairngorm Parsley Mate RobotLegs Swiz
  • 41. Modular features Yes No PureMVC (multicore) Cairngorm Mate PureMVC (standard) Parsley RobotLegs Swiz
  • 42. Community involvement Corporate Community Cairngorm Robotlegs Parsley Swiz Mate PureMVC
  • 43. History and evolution Generation 1.0 Cairngorm Out of date PureMVC Generation 1.5 Mature Mate Swiz Generation 2.0 Parsley Cutting edge RobotLegs
  • 44. This is me www.richardlord.net twitter.com/Richard_Lord