Developing Flex Applications with the Swiz Framework - PowerPoint PPT Presentation

About This Presentation
Title:

Developing Flex Applications with the Swiz Framework

Description:

... I think it is way better then Cairngorm!' Kurt Wiersma, some Mach-ii dude ... Sort of similar to Cairngorm's FrontController, but WAY less boilerplate code. 41 ... – PowerPoint PPT presentation

Number of Views:116
Avg rating:3.0/5.0
Slides: 47
Provided by: Liz273
Category:

less

Transcript and Presenter's Notes

Title: Developing Flex Applications with the Swiz Framework


1
Developing Flex Applications with the Swiz
Framework
  • Chris Scott

www.cfunited.com
2
About Me
  1. Enterprise Software Consultant
  2. Author of the Swiz Framework
  3. Co-Author of ColdSpring
  4. Contributor to too many OSS projects
  5. Developing with Flex, CF and Java for quite a
    long time

www.cfunited.com
3
What Well 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

www.cfunited.com
4
Another framework for Flex?
www.cfunited.com
5
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

www.cfunited.com
6
What Swiz users are saying...
  • Personally I think it is way better then
    Cairngorm!
  • Kurt Wiersma, some Mach-ii dude

www.cfunited.com
7
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

www.cfunited.com
8
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

www.cfunited.com
9
Why Swiz?
  1. Because those guys told you to?
  2. Not at all!! But Swiz is...
  3. Simple and effective!
  4. Easy to learn!
  5. Designed to help you write less code!
  6. Encourages loose coupling through MVC!
  7. More things that end with !!!...

www.cfunited.com
10
What is Swiz all about?
www.cfunited.com
11
Swiz Overview
  • Flex Applications Require
  • Remote Services
  • Models / Data
  • Controllers / Logic
  • Views

www.cfunited.com
12
Swiz Overview
  • Components need each other
  • Wire ourselves
  • Use Locators
  • Verbose XML

www.cfunited.com
13
Swiz Overview
  • Components need each other
  • Wire ourselves
  • Use Locators
  • Verbose XML
  • IoC
  • Annotations

www.cfunited.com
14
Swiz Overview
  • Views communicate with components
  • Flex Events
  • MVC Paradigm
  • DynamicMediatormakes it easy!

www.cfunited.com
15
Swiz Overview
  • Applications need remote data
  • Async Tokens
  • Responders
  • State around calls
  • DynamicRespondermakes it easy!

www.cfunited.com
16
Major Swiz Features
  • IoC
  • autowires app
  • DynamicResponder
  • remote data
  • DynamicMediator
  • event handling
  • and a whole lot more...

www.cfunited.com
17
What Swiz DOESNT Provide
  1. Excessive JEE patterns
  2. Boilerplate code
  3. Verbose XML / MXML configuration
  4. Overly Prescriptive workflow

www.cfunited.com
18
Inversion of Control, the Swiz way
How about a little audience participation...
www.cfunited.com
19
IoC Recap
  1. Components require dependencies to function
  2. Dependencies may be simple strings and values, or
    other components
  3. Resolving complex dependencies is outside the
    scope of primary logic

www.cfunited.com
20
Inversion of Control with Swiz
  1. Express dependencies through Metadata, or
    Annotations
  2. Swiz takes care of configuration through
    Dependency Injection
  3. Views also have dependencies such as Models, or
    PresentationModels
  4. Swiz handles everything for you!

www.cfunited.com
21
Working with Swiz
www.cfunited.com
22
Defining Beans
  1. Define components in BeanLoaders
  2. Written in plain old MXML
  3. Swiz calls objects Beans because it only cares
    about their properties
  4. only sort of true

www.cfunited.com
23
Defining BeanLoaders
  1. ltBeanLoader xmlnsorg.swizframework.util.
  2. xmlnsmxhttp//www.adobe.com/2006/mxmlgt
  3. ltmxRemoteObject iduserService
    destinationuserService/gt
  4. ltmxRemoteObject idmapService
    destinationmapService/gt
  5. ltcontrollerUserController iduserController
    /gt
  6. ltcontrollerMapController idmapController/gt
  7. lt/BeanLoadergt

www.cfunited.com
24
Swizs IoC Factory
  1. When Swiz loads beans, it searches for Autowire
    metadata
  2. When objects are retrieved, Swiz performs the
    magic of Autowiring
  3. Swiz adds event listeners for added to stage and
    removed from stage events
  4. Allows Swiz to Autowire and clean up Views too!

www.cfunited.com
25
Loading Swiz - Old Style...
  1. Load Swiz early, in a preinitialize handler
  2. Swiz constructs components for you to help manage
    your application
  3. Initialization is performed as soon as you do
    anything to Swiz, like loading beansprivate
    function onInitialize() void Swiz.loadBeans(
    Beans )

www.cfunited.com
26
Loading Swiz - New Style!
  1. Use Swizs ConfigBean in MXML
  2. Requires an array of BeanLoaders
  3. Access to all configuration parametersltswizframe
    workSwizConfig strict"true"
    beanLoaders"Beans" logEventLevel"LogE
    ventLevel.WARN"/gt

www.cfunited.com
27
Expressing Dependencies
  1. Dependencies are NOT defined in MXML!
  2. Use Autowire in your AS objects
  3. Similar to new Spring 2.0 configuration
  4. Qualify bean to inject by id.
  5. Autowire(bean"userController")public var
    userController UserController

www.cfunited.com
28
Expressing Dependencies
  1. To autowire by type, forget the bean
  2. Swiz looks for bean which matches the variable
    type
  3. Works with interfaces and inheritance
  4. Swiz throws AmbiguousBean error if more than
    one bean could be injected

www.cfunited.com
29
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
  • dont do this in Beans! Only in views!
  • there are better ways to perform initialization!

www.cfunited.com
30
Working with Remote Services
  • Swiz provides two simple methods for remote
    method calls
  • Both dynamically create responders for
    AsyncTokens
  • DynamicResponder
  • DynamicCommand

www.cfunited.com
31
Working with Remote Services
  1. DynamicResponders bind result and fault handlers
    transparently
  2. DynamicCommand is similar, but can be chained
    together and delayed
  3. Swiz offers simple methods for creating in
    AbstractController

www.cfunited.com
32
DynamicResponders
  1. executeServiceCall creates dynamic responders for
    you
  2. Implement iResponderexecuteServiceCall(userServic
    e.getUser,
    getUserResult)
  3. First parameter an AsyncToken, returned from a
    remote call
  4. Second parameter is the Function to be called in
    the responders onResult()

www.cfunited.com
33
DynamicResponders
  1. Third parameter is a Function to be called in the
    responders onFault()
  2. If you omit the fault parameter, Swiz uses a
    default fault handler
  3. Swiz can also bind extra parameters to your
    result handlers

www.cfunited.com
34
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

www.cfunited.com
35
DynamicCommands
  1. Similar to DynamicResponders, but first parameter
    is a Function which returns an AsyncToken
  2. The Function is called dynamically in the
    Commands execute() method
  3. Created for you with createCommand()createCommand
    (userDelegate.saveUser,
    user, saveUserResult)

www.cfunited.com
36
DynamicCommands
  1. Can be added to Swizs CommandChain
  2. Chains can run in series or parallel
  3. A final Function or Event is fired when the Chain
    completes
  4. You can attach a Function or Event for faults as
    well

www.cfunited.com
37
DynamicCommands
var chain new CommandChain() chain.addCommand(
createCommand( helloDelegate.echo, "swiz
rulz!", echo_results, local_Fault))
.addCommand(createCommand( helloDelegate.showT
ime, null, time_results, local_Fault)) ch
ain.completeHandler completeHandler chain.proce
ed()
www.cfunited.com
38
Event Handling with Swiz
  1. Swiz does not try to replace Flexs Event model,
    just adds a little simplicity
  2. Most apps contain a CentralDispatcher, Swiz just
    give you one for free
  3. Swiz abstracts its use through static methods

www.cfunited.com
39
Event Handling with Swiz
  • Swiz.dispatchEvent(eventEvent)
  • Dispatches any event (no Swiz event)
  • Swiz.dispatch(typeString)
  • Creates an event for you
  • Swiz.addEventListener(typeString,
    functionFunction, ... )
  • Adds an eventListener to Swizs CentralDispatcher

www.cfunited.com
40
DynamicMediators
  1. Greatly help to promote loose coupling between
    Views and Controllers
  2. Enables very simple event handling in Controllers
  3. Reduces repetitive glue code in Views
  4. Sort of similar to Cairngorms FrontController,
    but WAY less boilerplate code

www.cfunited.com
41
DynamicMediators
  1. Add Mediate annotation to a Controller function
  2. Mediate(eventeventType, propertiesfoo,
    bar)public function doStuff(argA String,
    argB String)
  3. Swiz creates a DynamicMediator for you
  4. Adds an eventListener for supplied type to Swizs
    centralDispatcher
  5. Uses properties to construct method call

www.cfunited.com
42
Strict type checking
  1. No compile time checking of event type strings
  2. Swiz.setStrict(true) forces Swiz to lookup event
    types from existing classes
  3. Can define base event packages with
    addEventPackage
  4. Swiz can write a proper missing event class to a
    log file

www.cfunited.com
43
Recap
  • Swizs 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

www.cfunited.com
44
Recap
  1. Swiz represents best practices learned from years
    of consulting
  2. Swiz is damn easy!
  3. New features are coming fast and furious!

www.cfunited.com
45
Resources
  1. Swiz Resources
  2. http//code.google.com/p/swizframework
  3. http//groups.google.com/group/swiz-framework
  4. http//cdscott.blogspot.com
  5. http//soenkerohde.com
  6. http//www.returnundefined.com
  7. Other Resources
  8. http//code.google.com/p/dphibernate
  9. http//code.google.com/p/flex-mojos
  10. http//code.google.com/p/loom

www.cfunited.com
46
Thank You!
  1. Chris ScottEnterprise Software Consultant
  2. http//cdscott.blogspot.comchris.scott.one_at_googl
    e.comasstrochris_at_comcast.netgtalk
    chris.scott.one_at_gmail.comaim/skype/twitter/plurk/
    brightkite asstrochris

www.cfunited.com
Write a Comment
User Comments (0)
About PowerShow.com