mvcExpress -
fastest and simplest
AS3 MVC frameworks

Raimundas Banevicius
Feb 14, 2012
Flash developer
1.   AS3 framework evolution
2.   simplicity
3.   performance
4.   extra perks




                               2
AS3 MVC Framework evolution
    Pros:
                                                                    Cons:

•    divide your code is small units        •     Slightly hurts performance
•    Good unit communication                •     Lot of boilerplate code.
•    Standardize your code
•    focus on app instead of architecture




+ Enforce TTD development                       - Hurts performance a lot
+ Removed most boilerplate code




                                            + Hurts performance the least
+ Enforce modular development
+ Simplifies code to the maximum            - Young framework


                                                                               3
AS3 MVC Framework evolution
    Pros:
                                                                    Cons:

•    divide your code is small units        •     Slightly hurts performance
•    Good unit communication                •     Lot of boilerplate code.
•    Standardize your code
•    focus on app instead of architecture




+ Enforce TTD development                       - Hurts performance a lot
+ Removed most boilerplate code




                                            + Hurts performance the least
+ Enforce modular development
+ Simplifies code to the maximum            - Young framework


                                                                               4
mvcExpress is simple!




                         5
mvcExpress is simple! – set up
• Set up PureMVC
   registerCommand((“startUp”, StartupCommand);

   registerProxy(new DataProxy());

   registerMediator(new GameMediator(new GameSprite()));

• Set up mvcExpress – MORE OPTIONS!
   commandMap.map(“startUp”, StartupCommand);

   commandMap.execute(AnotherCommand, new CommandParams());


   proxyMap.mapObject(new DataProxy());

   proxyMap.mapClass(DataProxy);

   mediatorMap.map(GameSprite, GameMediator);

   mediatorMap.mediate(new GameSprite());
                                                              6
mvcExpress is simple! – commands

• PureMVC:
  sendNotification(“new_message”);

    override public function execute(notice:INotification):void {
      // geting command parameters
      var params:ParamsVO = notice.getBody() as ParamsVO;

        // do stuff...
    }

• mvcExpress
  sendMessage(“new_message”);

    // geting command parameters
    public function execute(params:ParamsVO):void {

        // do stuff...
    }



                                                                    7
mvcExpress is simple! – getting stuff in commands

• PureMVC:
  // get data
  var dataProxy:DataProxy =
                facade.retrieveProxy(DataProxy.NAME) as DataProxy;


  // get mediator
   var testMediator:ViewMediator =
        facade.retrieveMediator(ViewMediator.NAME) as ViewMediator;

• mvcExpress
  // get data
  [Inject]
  public var dataProxy:DataProxy;


  // get mediator

     NOT POSSIBLE!!!
       It is bad practice to use mediators from commands.

                                                                      8
mvcExpress is simple! – Proxies

• PureMVC:
  public class PureMvcProxy extends Proxy implements IProxy {
    public static const NAME:String = "PureMvcProxy";

      public function PureMvcProxy() {
        var proxyData:DataVO = new DataVO();
        super(NAME, proxyData);
      }

      // get and cast data object for convenience..
      public function get dataVo():DataVO {
         return super.getData() as DataVO;
      }
  }
• mvcExpress
  public class MvcExpressProxy extends Proxy {

      private var dataVO:DataVO = new DataVO();

      public function MvcExpressProxy() {
      }
  }
                                                                9
mvcExpress is simple! – Mediator+View:
• PureMVC:
  public class PureMvcMediator extends Mediator implements IMediator {
    public static const NAME:String = "PureMvcMediator";

    public function PureMvcMediator(initViewComponent:ViewComponent) {
      super(NAME, initViewComponent);
    }

    // cast view for convenient local use.
    public function get view():ViewComponent {
        return super.getViewComponent() as ViewComponent;
    }

    // listen for framework notices
    override public function listNotificationInterests():Array {
        return [ //
           DataNote.STUFF_DONE //
           ];
    }

    // handle framework events
    override public function handleNotification(notice:INotification):void {
        switch (notice.getName()) {
          case DataNote.STUFF_DONE:
             // do stuff…
          break;
  } } }                                                                        10
mvcExpress is simple! – Mediator+View:
• PureMVC:
  public class PureMvcMediator extends Mediator implements IMediator {
    public static const NAME:String = "PureMvcMediator";

    public function PureMvcMediator(initViewComponent:ViewComponent) {
      super(NAME, initViewComponent);
    }

    // cast view for convenient local use.
    public function get view():ViewComponent {
        return super.getViewComponent() as ViewComponent;
    }

    // listen for framework notices
    override public function listNotificationInterests():Array {
        return [ //
           DataNote.STUFF_DONE //
           ];
    }

    // handle framework events
    override public function handleNotification(notice:INotification):void {
        switch (notice.getName()) {
          case DataNote.STUFF_DONE:
             // do stuff…
          break;
  } } }                                                                        11
mvcExpress is simple! – Mediator+View:
• mvcExpress:
  public class MvcExpressMediator extends Mediator {

      [Inject]
      public var view:ViewComponent;

      override public function onRegister():void {
        // listen for framework events
        addHandler(DataNote.STUFF_DONE, handleStuffDone);
      }

      // handle framework events
      private function handleStuffDone(params:DataChangeParamsVO):void {
          view.showStuff(params.dataParam1);
      }
  }




                                                                           12
mvcExpress is fast!




                       13
mvcExpress is fast! - Command execution

                      1600

                      1400

                      1200
Executions per 1 ms




                      1000

                      800                                                            RobotLegs
                                                                                     PureMVC
                      600
                                                                                     mvcExpress
                      400

                      200

                        0
                             with nothing:      with      with Model:   Model and
                                             parameter:                 View call:

                                                                                                  14
mvcExpress is fast! - Command execution

                      1600

                      1400

                      1200
Executions per 1 ms




                      1000

                      800                                                            RobotLegs
                                                                                     PureMVC
                      600
                                                                                     mvcExpress
                      400

                      200

                        0
                             with nothing:      with      with Model:   Model and
                                             parameter:                 View call:

                                                                                                  15
mvcExpress is fast! - mediator registering / removal

                      100
                      90
                      80
Executions per 1 ms




                      70
                      60
                      50                                                      RobotLegs
                      40                                                      PureMVC
                      30                                                      mvcExpress

                      20
                      10
                       0
                            Register Register Register Remove Remove Remove
                             1000:    2000:    5000:    1000:  2000:  5000:

                                                                                           16
mvcExpress is fast! - mediator registering / removal

                      100
                      90
                      80
Executions per 1 ms




                      70
                      60
                      50                                                      RobotLegs
                      40                                                      PureMVC
                      30                                                      mvcExpress

                      20
                      10
                       0
                            Register Register Register Remove Remove Remove
                             1000:    2000:    5000:    1000:  2000:  5000:

                                                                                           17
mvcExpress is fast! – communication speed

                      25000


                      20000
Executions per 1 ms




                      15000

                                                                                        RobotLegs
                      10000
                                                                                        PureMVC
                                                                                        mvcExpress
                      5000


                          0
                              1 receiving   100        200        500        1000
                              mediators: receiving receiving receiving receiving
                                          mediators: mediators: mediators: mediators:

                                                                                                     18
mvcExpress is fast! – communication speed

                      25000


                      20000
Executions per 1 ms




                      15000

                                                                                        RobotLegs
                      10000
                                                                                        PureMVC
                                                                                        mvcExpress
                      5000


                          0
                              1 receiving   100        200        500        1000
                              mediators: receiving receiving receiving receiving
                                          mediators: mediators: mediators: mediators:

                                                                                                     19
Extra perks


• Hard to misuse:
In mvcExpress you will have - what you need, where you need it.
No more no less.


• Modular:
Want it or not – you will be creating reusable modules by extending
ModuleCore.as class.



• Helps avoid errors:
mvcExpress uses conditional compilation very extensively!
Add ”-define+=CONFIG::DEBUG,true” to benefit from better error checking and
warnings.

                                                                              20
Check it out!


• Code on gitHub:
https://github.com/MindScriptAct/mvcExpress-framework



• mvcExpress homePage:
http://mvcexpress.org/




• My blog:
http://www.mindscriptact.com/




                                                        21
Thank you for your time!


            Questions?




                            22

Mvc express presentation

  • 1.
    mvcExpress - fastest andsimplest AS3 MVC frameworks Raimundas Banevicius Feb 14, 2012 Flash developer
  • 2.
    1. AS3 framework evolution 2. simplicity 3. performance 4. extra perks 2
  • 3.
    AS3 MVC Frameworkevolution Pros: Cons: • divide your code is small units • Slightly hurts performance • Good unit communication • Lot of boilerplate code. • Standardize your code • focus on app instead of architecture + Enforce TTD development - Hurts performance a lot + Removed most boilerplate code + Hurts performance the least + Enforce modular development + Simplifies code to the maximum - Young framework 3
  • 4.
    AS3 MVC Frameworkevolution Pros: Cons: • divide your code is small units • Slightly hurts performance • Good unit communication • Lot of boilerplate code. • Standardize your code • focus on app instead of architecture + Enforce TTD development - Hurts performance a lot + Removed most boilerplate code + Hurts performance the least + Enforce modular development + Simplifies code to the maximum - Young framework 4
  • 5.
  • 6.
    mvcExpress is simple!– set up • Set up PureMVC registerCommand((“startUp”, StartupCommand); registerProxy(new DataProxy()); registerMediator(new GameMediator(new GameSprite())); • Set up mvcExpress – MORE OPTIONS! commandMap.map(“startUp”, StartupCommand); commandMap.execute(AnotherCommand, new CommandParams()); proxyMap.mapObject(new DataProxy()); proxyMap.mapClass(DataProxy); mediatorMap.map(GameSprite, GameMediator); mediatorMap.mediate(new GameSprite()); 6
  • 7.
    mvcExpress is simple!– commands • PureMVC: sendNotification(“new_message”); override public function execute(notice:INotification):void { // geting command parameters var params:ParamsVO = notice.getBody() as ParamsVO; // do stuff... } • mvcExpress sendMessage(“new_message”); // geting command parameters public function execute(params:ParamsVO):void { // do stuff... } 7
  • 8.
    mvcExpress is simple!– getting stuff in commands • PureMVC: // get data var dataProxy:DataProxy = facade.retrieveProxy(DataProxy.NAME) as DataProxy; // get mediator var testMediator:ViewMediator = facade.retrieveMediator(ViewMediator.NAME) as ViewMediator; • mvcExpress // get data [Inject] public var dataProxy:DataProxy; // get mediator NOT POSSIBLE!!! It is bad practice to use mediators from commands. 8
  • 9.
    mvcExpress is simple!– Proxies • PureMVC: public class PureMvcProxy extends Proxy implements IProxy { public static const NAME:String = "PureMvcProxy"; public function PureMvcProxy() { var proxyData:DataVO = new DataVO(); super(NAME, proxyData); } // get and cast data object for convenience.. public function get dataVo():DataVO { return super.getData() as DataVO; } } • mvcExpress public class MvcExpressProxy extends Proxy { private var dataVO:DataVO = new DataVO(); public function MvcExpressProxy() { } } 9
  • 10.
    mvcExpress is simple!– Mediator+View: • PureMVC: public class PureMvcMediator extends Mediator implements IMediator { public static const NAME:String = "PureMvcMediator"; public function PureMvcMediator(initViewComponent:ViewComponent) { super(NAME, initViewComponent); } // cast view for convenient local use. public function get view():ViewComponent { return super.getViewComponent() as ViewComponent; } // listen for framework notices override public function listNotificationInterests():Array { return [ // DataNote.STUFF_DONE // ]; } // handle framework events override public function handleNotification(notice:INotification):void { switch (notice.getName()) { case DataNote.STUFF_DONE: // do stuff… break; } } } 10
  • 11.
    mvcExpress is simple!– Mediator+View: • PureMVC: public class PureMvcMediator extends Mediator implements IMediator { public static const NAME:String = "PureMvcMediator"; public function PureMvcMediator(initViewComponent:ViewComponent) { super(NAME, initViewComponent); } // cast view for convenient local use. public function get view():ViewComponent { return super.getViewComponent() as ViewComponent; } // listen for framework notices override public function listNotificationInterests():Array { return [ // DataNote.STUFF_DONE // ]; } // handle framework events override public function handleNotification(notice:INotification):void { switch (notice.getName()) { case DataNote.STUFF_DONE: // do stuff… break; } } } 11
  • 12.
    mvcExpress is simple!– Mediator+View: • mvcExpress: public class MvcExpressMediator extends Mediator { [Inject] public var view:ViewComponent; override public function onRegister():void { // listen for framework events addHandler(DataNote.STUFF_DONE, handleStuffDone); } // handle framework events private function handleStuffDone(params:DataChangeParamsVO):void { view.showStuff(params.dataParam1); } } 12
  • 13.
  • 14.
    mvcExpress is fast!- Command execution 1600 1400 1200 Executions per 1 ms 1000 800 RobotLegs PureMVC 600 mvcExpress 400 200 0 with nothing: with with Model: Model and parameter: View call: 14
  • 15.
    mvcExpress is fast!- Command execution 1600 1400 1200 Executions per 1 ms 1000 800 RobotLegs PureMVC 600 mvcExpress 400 200 0 with nothing: with with Model: Model and parameter: View call: 15
  • 16.
    mvcExpress is fast!- mediator registering / removal 100 90 80 Executions per 1 ms 70 60 50 RobotLegs 40 PureMVC 30 mvcExpress 20 10 0 Register Register Register Remove Remove Remove 1000: 2000: 5000: 1000: 2000: 5000: 16
  • 17.
    mvcExpress is fast!- mediator registering / removal 100 90 80 Executions per 1 ms 70 60 50 RobotLegs 40 PureMVC 30 mvcExpress 20 10 0 Register Register Register Remove Remove Remove 1000: 2000: 5000: 1000: 2000: 5000: 17
  • 18.
    mvcExpress is fast!– communication speed 25000 20000 Executions per 1 ms 15000 RobotLegs 10000 PureMVC mvcExpress 5000 0 1 receiving 100 200 500 1000 mediators: receiving receiving receiving receiving mediators: mediators: mediators: mediators: 18
  • 19.
    mvcExpress is fast!– communication speed 25000 20000 Executions per 1 ms 15000 RobotLegs 10000 PureMVC mvcExpress 5000 0 1 receiving 100 200 500 1000 mediators: receiving receiving receiving receiving mediators: mediators: mediators: mediators: 19
  • 20.
    Extra perks • Hardto misuse: In mvcExpress you will have - what you need, where you need it. No more no less. • Modular: Want it or not – you will be creating reusable modules by extending ModuleCore.as class. • Helps avoid errors: mvcExpress uses conditional compilation very extensively! Add ”-define+=CONFIG::DEBUG,true” to benefit from better error checking and warnings. 20
  • 21.
    Check it out! •Code on gitHub: https://github.com/MindScriptAct/mvcExpress-framework • mvcExpress homePage: http://mvcexpress.org/ • My blog: http://www.mindscriptact.com/ 21
  • 22.
    Thank you foryour time!   Questions? 22