Www.cfunited.com Developing Flex Applications with the Swiz Framework Chris Scott.

download Www.cfunited.com Developing Flex Applications with the Swiz Framework Chris Scott.

If you can't read please download the document

Transcript of Www.cfunited.com Developing Flex Applications with the Swiz Framework Chris Scott.

  • Slide 1

www.cfunited.com Developing Flex Applications with the Swiz Framework Chris Scott Slide 2 2 www.cfunited.com About Me A.Enterprise Software Consultant B.Author of the Swiz Framework C.Co-Author of ColdSpring D.Contributor to too many OSS projects E.Developing with Flex, CF and Java for quite a long time Slide 3 3 www.cfunited.com What Well Cover A.What, Why, How What is Swiz? Why should you use it? How does Swiz make your life easier? Why do I have such a hangover? B.Advanced Swiz C.New Features Slide 4 4 www.cfunited.com Another framework for Flex? Slide 5 5 www.cfunited.com What Swiz users are saying... A.Broadchoice evaluated a few frameworks and settled on Swiz as the keystone behind our Workspace product. Sean Corfield, CTO Railo US Slide 6 6 www.cfunited.com What Swiz users are saying... A.Personally I think it is way better then Cairngorm! Kurt Wiersma, some Mach-ii dude Slide 7 7 www.cfunited.com What Swiz users are saying... A.Swiz is a lovely, lightweight framework that I'm really enjoying working with. Aral Balkan, a popular Flash blogger and CF hater Slide 8 8 www.cfunited.com What Swiz users are saying... A.Even bigger thanks for Swiz... Which is one of the most elegant and useful pieces of software that I've ever seen in my 24 years of programming! Afik Gal, a guy I do not know at all Slide 9 9 www.cfunited.com Why Swiz? A.Because those guys told you to? B.Not at all!! But Swiz is... C.Simple and effective! D.Easy to learn! E.Designed to help you write less code! F.Encourages loose coupling through MVC! G.More things that end with !!!... Slide 10 10 www.cfunited.com What is Swiz all about? Slide 11 11 www.cfunited.com Swiz Overview A.Flex Applications Require: Remote Services Models / Data Controllers / Logic Views Slide 12 12 www.cfunited.com Swiz Overview A.Components need each other Wire ourselves Use Locators Verbose XML Slide 13 13 www.cfunited.com Swiz Overview A.Components need each other Wire ourselves Use Locators Verbose XML IoC Annotations Slide 14 14 www.cfunited.com Swiz Overview A.Views communicate with components Flex Events MVC Paradigm DynamicMediator makes it easy! Slide 15 15 www.cfunited.com Swiz Overview A.Applications need remote data Async Tokens Responders State around calls DynamicResponder makes it easy! Slide 16 16 www.cfunited.com Major Swiz Features A.IoC autowires app B.DynamicResponder remote data C.DynamicMediator event handling D.and a whole lot more... Slide 17 17 www.cfunited.com What Swiz DOESNT Provide A.Excessive JEE patterns B.Boilerplate code C.Verbose XML / MXML configuration D.Overly Prescriptive workflow Slide 18 18 www.cfunited.com Inversion of Control, the Swiz way How about a little audience participation... Slide 19 19 www.cfunited.com IoC Recap A.Components require dependencies to function B.Dependencies may be simple strings and values, or other components C.Resolving complex dependencies is outside the scope of primary logic Slide 20 20 www.cfunited.com Inversion of Control with Swiz A.Express dependencies through Metadata, or Annotations B.Swiz takes care of configuration through Dependency Injection C.Views also have dependencies such as Models, or PresentationModels D.Swiz handles everything for you! Slide 21 21 www.cfunited.com Working with Swiz Slide 22 22 www.cfunited.com Defining Beans A.Define components in BeanLoaders B.Written in plain old MXML C.Swiz calls objects Beans because it only cares about their properties* D. * only sort of true Slide 23 23 www.cfunited.com Defining BeanLoaders A.mx=http://www.adobe.com/2006/m C. D. E. F. G. Slide 24 24 www.cfunited.com Swizs IoC Factory A.When Swiz loads beans, it searches for Autowire metadata B.When objects are retrieved, Swiz performs the magic of Autowiring C.Swiz adds event listeners for added to stage and removed from stage events D.Allows Swiz to Autowire and clean up Views too! Slide 25 25 www.cfunited.com Loading Swiz - Old Style... A.Load Swiz early, in a preinitialize handler B.Swiz constructs components for you to help manage your application C.Initialization is performed as soon as you do anything to Swiz, like loading beans private function onInitialize() : void { Swiz.loadBeans( [ Beans ] ); } Slide 26 "> 26 www.cfunited.com Loading Swiz - New Style! A.Use Swizs ConfigBean in MXML B.Requires an array of BeanLoaders C.Access to all configuration parametersSlide 27 27 www.cfunited.com Expressing Dependencies A.Dependencies are NOT defined in MXML! B.Use [Autowire] in your AS objects C.Similar to new Spring 2.0 configuration D.Qualify bean to inject by id. E. [Autowire(bean="userController")] public var userController: UserController; Slide 28 28 www.cfunited.com Expressing Dependencies A.To autowire by type, forget the bean B.Swiz looks for bean which matches the variable type C.Works with interfaces and inheritance D.Swiz throws AmbiguousBean error if more than one bean could be injected Slide 29 29 www.cfunited.com View Autowiring A.You can use Autowire on accessors as well as properties B.Properties can be autowired with two way bindings!! C.Accessors allow views to perform logic when dependencies are set dont do this in Beans! Only in views! there are better ways to perform initialization! Slide 30 30 www.cfunited.com Working with Remote Services A.Swiz provides two simple methods for remote method calls B.Both dynamically create responders for AsyncTokens DynamicResponder DynamicCommand Slide 31 31 www.cfunited.com Working with Remote Services A.DynamicResponders bind result and fault handlers transparently B.DynamicCommand is similar, but can be chained together and delayed C.Swiz offers simple methods for creating in AbstractController Slide 32 32 www.cfunited.com DynamicRespondersDynamicResponders A.executeServiceCall creates dynamic responders for you B.Implement iResponder executeServiceCall(userService.getUser, getUserResult); C.First parameter an AsyncToken, returned from a remote call D.Second parameter is the Function to be called in the responders onResult() Slide 33 33 www.cfunited.com DynamicRespondersDynamicResponders A.Third parameter is a Function to be called in the responders onFault() B.If you omit the fault parameter, Swiz uses a default fault handler C.Swiz can also bind extra parameters to your result handlers Slide 34 34 www.cfunited.com Binding data to result handlers A.Passed as an array to executeServiceCall B.Swiz treats this as extra arguments to pass to your result handler C.Allows you maintain state over async calls ex. Pass User being saved to ResultHander Slide 35 35 www.cfunited.com DynamicCommandsDynamicCommands A.Similar to DynamicResponders, but first parameter is a Function which returns an AsyncToken B.The Function is called dynamically in the Commands execute() method C.Created for you with createCommand() createCommand(userDelegate.saveUser, [user], saveUserResult); Slide 36 36 www.cfunited.com DynamicCommandsDynamicCommands A.Can be added to Swizs CommandChain B.Chains can run in series or parallel C.A final Function or Event is fired when the Chain completes D.You can attach a Function or Event for faults as well Slide 37 37 www.cfunited.com DynamicCommandsDynamicCommands var chain : new CommandChain(); chain.addCommand(createCommand( helloDelegate.echo, ["swiz rulz!"], echo_results, local_Fault)).addCommand(createCommand( helloDelegate.showTime, null, time_results, local_Fault)); chain.completeHandler = completeHandler; chain.proceed(); Slide 38 38 www.cfunited.com Event Handling with Swiz A.Swiz does not try to replace Flexs Event model, just adds a little simplicity B.Most apps contain a CentralDispatcher, Swiz just give you one for free C.Swiz abstracts its use through static methods Slide 39 39 www.cfunited.com Event Handling with Swiz A.Swiz.dispatchEvent(event:Event); Dispatches any event (no Swiz event) B.Swiz.dispatch(type:String); Creates an event for you C.Swiz.addEventListener(type:String, function:Function,... ); Adds an eventListener to Swizs CentralDispatcher Slide 40 40 www.cfunited.com DynamicMediatorsDynamicMediators A.Greatly help to promote loose coupling between Views and Controllers B.Enables very simple event handling in Controllers C.Reduces repetitive glue code in Views D.Sort of similar to Cairngorms FrontController, but WAY less boilerplate code Slide 41 41 www.cfunited.com DynamicMediatorsDynamicMediators A.Add [Mediate] annotation to a Controller function B.[Mediate(event=eventType, properties=foo, bar)] public function doStuff(argA : String, argB : String) {} C.Swiz creates a DynamicMediator for you D.Adds an eventListener for supplied type to Swizs centralDispatcher E.Uses properties to construct method call Slide 42 42 www.cfunited.com Strict type checking A.No compile time checking of event type strings B.Swiz.setStrict(true) forces Swiz to lookup event types from existing classes C.Can define base event packages with addEventPackage D.Swiz can write a proper missing event class to a log file Slide 43 43 www.cfunited.com RecapRecap A.Swizs IoC is very easy to use B.Swiz provides a simple MVC paradigm C.Very little XML! Mostly Annotations D.Swiz provides core utilities for: DynamicResponders and Commands Event handling DynamicMediators Slide 44 44 www.cfunited.com RecapRecap A.Swiz represents best practices learned from years of consulting B.Swiz is damn easy! C.New features are coming fast and furious! Slide 45 45 www.cfunited.com ResourcesResources A.Swiz Resources B.http://code.google.com/p/swizframeworkhttp://code.google.com/p/swizframework C.http://groups.google.com/group/swiz-frameworkhttp://groups.google.com/group/swiz-framework D.http://cdscott.blogspot.comhttp://cdscott.blogspot.com E.http://soenkerohde.comhttp://soenkerohde.com F.http://www.returnundefined.comhttp://www.returnundefined.com G.Other Resources H.http://code.google.com/p/dphibernatehttp://code.google.com/p/dphibernate I.http://code.google.com/p/flex-mojos J.http://code.google.com/p/loomhttp://code.google.com/p/loom Slide 46 46 www.cfunited.com Thank You! A. Chris Scott Enterprise Software Consultant B.http://cdscott.blogspot.com [email protected] [email protected] gtalk: [email protected] aim/skype/twitter/plurk/brightkite: asstrochrishttp://cdscott.blogspot.co [email protected] [email protected] [email protected]