对比下比较热门的几个as3 MVC 框架:
Framework | Dependencies Management | Event Management | Presentation Pattern |
Cairngorm | Singleton | Singleton Dispatcher | Code Behind |
PureMVC | Service Locator | Notification | Mediator |
Mate | Dependency Injection | Display list | Presentation Model |
Swiz | Dependency Injection | Display list | Presentation Model |
Parsley | Dependency Injection | Central Dispatcher | Presentation Model |
Robotlegs | Dependency Injection | Event bus | Mediator or others |
pureMVC运用范围不仅限与actionscript ,同样可以应用到其它语言java,.net 等 ,它基于INotification,而不是as 自身的event事件,所以效率和灵活度大大提高了。
同时pureMVC如果运用不合理可能超成繁冗工作量可能会增加不少。
robotlegs的MVC框架,发现借鉴了很多puremvc的思想,相比之下robotlegs 更加专注入AS3,吸收了puremvc的优点,同时引入 依赖注入模式,类似java中的spring.
它使用了SwiftSuspenders 框架实现actionscript 中的依赖注入,并对它进行了相应的封装。
SwiftSuspenders :https://github.com/tschneidereit/SwiftSuspenders/
这里我写了两个简单的DEMO,一个是pureMVC和robotlegs(robotlegs DEMO好像很少)
个人觉得robotlegs更加好用!希望对大家入门有一定的帮助。
相关资料:
https://github.com/robotlegs/robotlegs-documentation/blob/master/best-practices-zh-cn.textile#mediatorresponsibilities
http://www.cnblogs.com/skynet/archive/2012/03/21/2410042.html
http://sswilliam.blog.163.com/blog/static/189696383201176112822269/