Developing flex applications with the swiz framework
1 / 46

Developing Flex Applications with the Swiz Framework - PowerPoint PPT Presentation

  • Uploaded on

Developing Flex Applications with the Swiz Framework. Chris Scott. About Me. Enterprise Software Consultant Author of the Swiz Framework Co-Author of ColdSpring Contributor to too many OSS projects Developing with Flex, CF and Java for quite a long time.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Developing Flex Applications with the Swiz Framework' - beatrix

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

About me l.jpg
About Me

  • Enterprise Software Consultant

  • Author of the Swiz Framework

  • Co-Author of ColdSpring

  • Contributor to too many OSS projects

  • Developing with Flex, CF and Java for quite a long time

What we ll cover l.jpg
What We’ll Cover

  • 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?

  • Advanced Swiz

  • New Features

Slide4 l.jpg

Another framework for Flex?

What swiz users are saying l.jpg
What Swiz users are saying...

  • “Broadchoice evaluated a few frameworks and settled on Swiz as the keystone behind our Workspace product.”

    • Sean Corfield, CTO Railo US

What swiz users are saying6 l.jpg
What Swiz users are saying...

  • “Personally I think it is way better then Cairngorm!”

    • Kurt Wiersma, some Mach-ii dude

What swiz users are saying7 l.jpg
What Swiz users are saying...

  • “Swiz is a lovely, lightweight framework that I'm really enjoying working with.”

    • Aral Balkan, a popular Flash blogger and CF hater

What swiz users are saying8 l.jpg
What Swiz users are saying...

  • “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

Why swiz l.jpg
Why Swiz?

  • Because those guys told you to?

  • Not at all!! But Swiz is...

  • Simple and effective!

  • Easy to learn!

  • Designed to help you write less code!

  • Encourages loose coupling through MVC!

  • More things that end with !!!...

Slide10 l.jpg

What is Swiz all about?

Swiz overview l.jpg
Swiz Overview

  • Flex Applications Require:

    • Remote Services

    • Models / Data

    • Controllers / Logic

    • Views

Swiz overview12 l.jpg
Swiz Overview

  • Components need each other

    • Wire ourselves

    • Use Locators

    • Verbose XML

Swiz overview13 l.jpg
Swiz Overview

  • Components need each other

    • Wire ourselves

    • Use Locators

    • Verbose XML

    • IoC

    • Annotations

Swiz overview14 l.jpg
Swiz Overview

  • Views communicate with components

    • Flex Events

    • MVC Paradigm

    • DynamicMediatormakes it easy!

Swiz overview15 l.jpg
Swiz Overview

  • Applications need remote data

    • Async Tokens

    • Responders

    • State around calls

    • DynamicRespondermakes it easy!

Major swiz features l.jpg
Major Swiz Features

  • IoC

    • autowires app

  • DynamicResponder

    • remote data

  • DynamicMediator

    • event handling

  • and a whole lot more...

What swiz doesn t provide l.jpg
What Swiz DOESN’T Provide

  • Excessive JEE patterns

  • Boilerplate code

  • Verbose XML / MXML configuration

  • Overly Prescriptive workflow

Inversion of control the swiz way l.jpg
Inversion of Control, the Swiz way

How about a little audience participation...

Ioc recap l.jpg
IoC Recap

  • Components require ‘dependencies’ to function

  • Dependencies may be simple strings and values, or other components

  • Resolving complex dependencies is outside the scope of primary logic

Inversion of control with swiz l.jpg
Inversion of Control with Swiz

  • Express dependencies through Metadata, or ‘Annotations’

  • Swiz takes care of configuration through Dependency Injection

  • Views also have dependencies such as Models, or PresentationModels

  • Swiz handles everything for you!

Slide21 l.jpg

Working with Swiz

Defining beans l.jpg
Defining Beans

  • Define components in BeanLoaders

  • Written in plain old MXML

  • Swiz calls objects Beans because it only cares about their properties*

  • * only sort of true…

Defining beanloaders l.jpg
Defining BeanLoaders

  • <BeanLoader xmlns=“org.swizframework.util.*”

  • xmlns:mx=>

  • <mx:RemoteObject id=“userService” destination=“userService”/>

  • <mx:RemoteObject id=“mapService” destination=“mapService”/>

  • <controller:UserController id=“userController”/>

  • <controller:MapController id=“mapController”/>

  • </BeanLoader>

Swiz s ioc factory l.jpg
Swiz’s IoC Factory

  • When Swiz loads beans, it searches for ‘Autowire’ metadata

  • When objects are retrieved, Swiz performs the magic of Autowiring

  • Swiz adds event listeners for added to stage and removed from stage events

  • Allows Swiz to Autowire and clean up Views too!

Loading swiz old style l.jpg
Loading Swiz - Old Style...

  • Load Swiz early, in a preinitialize handler

  • Swiz constructs components for you to help manage your application

  • Initialization is performed as soon as you do anything to Swiz, like loading beansprivate function onInitialize() : void { Swiz.loadBeans( [ Beans ] );}

Loading swiz new style l.jpg
Loading Swiz - New Style!

  • Use Swiz’s ConfigBean in MXML

  • Requires an array of BeanLoaders

  • Access to all configuration parameters<swizframework:SwizConfig strict="true" beanLoaders="{[Beans]}" logEventLevel="{LogEventLevel.WARN}"/>

Expressing dependencies l.jpg
Expressing Dependencies

  • Dependencies are NOT defined in MXML!

  • Use [Autowire] in your AS objects

  • Similar to new Spring 2.0 configuration

  • Qualify bean to inject by id.

  • [Autowire(bean="userController")]public var userController: UserController;

Expressing dependencies28 l.jpg
Expressing Dependencies

  • To autowire by type, forget the ‘bean’

  • Swiz looks for bean which matches the variable type

  • Works with interfaces and inheritance

  • Swiz throws ‘AmbiguousBean’ error if more than one bean could be injected

View autowiring l.jpg
View Autowiring

  • You can use Autowire on accessors as well as properties

  • Properties can be autowired with two way bindings!!

  • Accessors allow views to perform logic when dependencies are set

    • don’t do this in Beans! Only in views!

    • there are better ways to perform initialization!

Working with remote services l.jpg
Working with Remote Services

  • Swiz provides two simple methods for remote method calls

  • Both dynamically create responders for AsyncTokens

    • DynamicResponder

    • DynamicCommand

Working with remote services31 l.jpg
Working with Remote Services

  • DynamicResponders bind result and fault handlers transparently

  • DynamicCommand is similar, but can be chained together and delayed

  • Swiz offers simple methods for creating in AbstractController

Dynamicresponders l.jpg

  • executeServiceCall creates dynamic responders for you

  • Implement iResponderexecuteServiceCall(userService.getUser, getUserResult);

  • First parameter an AsyncToken, returned from a remote call

  • Second parameter is the Function to be called in the responder’s onResult()

Dynamicresponders33 l.jpg

  • Third parameter is a Function to be called in the responder’s onFault()

  • If you omit the fault parameter, Swiz uses a default fault handler

  • Swiz can also bind extra parameters to your result handlers

Binding data to result handlers l.jpg
Binding data to result handlers

  • Passed as an array to executeServiceCall

  • Swiz treats this as extra arguments to pass to your result handler

  • Allows you maintain state over async calls

    • ex. Pass User being saved to ResultHander

Dynamiccommands l.jpg

  • Similar to DynamicResponders, but first parameter is a Function which returns an AsyncToken

  • The Function is called dynamically in the Command’s execute() method

  • Created for you with createCommand()createCommand(userDelegate.saveUser, [user], saveUserResult);

Dynamiccommands36 l.jpg

  • Can be added to Swiz’s CommandChain

  • Chains can run in series or parallel

  • A final Function or Event is fired when the Chain completes

  • You can attach a Function or Event for faults as well

Dynamiccommands37 l.jpg

  • 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();

Event handling with swiz l.jpg
Event Handling with Swiz

  • Swiz does not try to replace Flex’s Event model, just adds a little simplicity

  • Most apps contain a CentralDispatcher, Swiz just give you one for free

  • Swiz abstracts its use through static methods

Event handling with swiz39 l.jpg
Event Handling with Swiz

  • Swiz.dispatchEvent(event:Event);

    • Dispatches any event (no Swiz event)

  • Swiz.dispatch(type:String);

    • Creates an event for you

  • Swiz.addEventListener(type:String, function:Function, ... );

    • Adds an eventListener to Swiz’s CentralDispatcher

Dynamicmediators l.jpg

  • Greatly help to promote loose coupling between Views and Controllers

  • Enables very simple event handling in Controllers

  • Reduces repetitive glue code in Views

  • Sort of similar to Cairngorm’s FrontController, but WAY less boilerplate code

Dynamicmediators41 l.jpg

  • Add [Mediate] annotation to a Controller function

  • [Mediate(event=“eventType”, properties=“foo, bar”)]public function doStuff(argA : String, argB : String) {}

  • Swiz creates a DynamicMediator for you

  • Adds an eventListener for supplied type to Swiz’s centralDispatcher

  • Uses ‘properties’ to construct method call

Strict type checking l.jpg
Strict type checking

  • No compile time checking of event type strings

  • Swiz.setStrict(true) forces Swiz to lookup event types from existing classes

  • Can define base event packages with addEventPackage

  • Swiz can write a proper missing event class to a log file

Recap l.jpg

  • Swiz’s IoC is very easy to use

  • Swiz provides a simple MVC paradigm

  • Very little XML! Mostly Annotations

  • Swiz provides core utilities for:

    • DynamicResponders and Commands

    • Event handling

    • DynamicMediators

Recap44 l.jpg

  • Swiz represents best practices learned from years of consulting

  • Swiz is damn easy!

  • New features are coming fast and furious!

Resources l.jpg

  • Swiz Resources






  • Other Resources




Thank you l.jpg
Thank You!

  • Chris ScottEnterprise Software Consultant

  • asstrochris