Download - Swiz DAO
![Page 2: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/2.jpg)
What we'll discussDI/ IoC IntroductionView PatternsWhat, Why, How
What is Swiz?Why should you use it?
Advanced SwizSwiz DAO
![Page 3: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/3.jpg)
What the Hell is IoC?Inversion of Control, is... design in which the flow of control of a system is inverted...-Wikipedia
Separate configuration from executionPromotes encapsulationPromotes simpler, focused components
![Page 4: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/4.jpg)
What the Hell is IoC?Reusing your code in efficient way.Consider CRUD Operations Logic or any logic being written once and used across your application. Coding Logic not being repeated will help you in efficient testing.Dependency Injection helps you [Inject] Objects and get use of deferred instantiation.Context helps you have a hold on whole application.
![Page 5: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/5.jpg)
IoC / Dependency Injection
The Inversion of Control (IoC) and Dependency Injection (DI) patterns are all about removing dependencies from your code.IoC/DI are not technologies, they are methods.The Hollywood principle "Don't call us, we'll call you".
![Page 6: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/6.jpg)
IoC / Dependency Injection
For example:
public class TextEditor{ private SpellChecker checker; public function TextEditor() { checker = new SpellChecker(); }}
What we've done here is create a dependency between the TextEditor and the SpellChecker.
![Page 7: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/7.jpg)
IoC / Dependency Injection
In an IoC scenario we would instead do something like this:public class TextEditor{ private ISpellChecker checker; public function TextEditor(ISpellChecker checker) { this.checker = checker; }}
Now, while creating the TextEditor class you have the control over which SpellChecker implementation to use. We're injecting the TextEditor with the dependency.
![Page 8: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/8.jpg)
View Patterns Hierarchy
![Page 9: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/9.jpg)
MVP PatternsPassive View Supervising Controller
Both variants allow you to increase the testability of your presentation logic.
![Page 10: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/10.jpg)
MVP Patterns
Passive View
![Page 11: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/11.jpg)
MVP Patterns
Supervising Controller
![Page 12: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/12.jpg)
Presentation Model
![Page 13: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/13.jpg)
Why not Traditional MVC?
You want to maximize the code that can be tested with automation. (Views are hard to test.)You want to share code between pages that require the same behavior.You want to separate business logic from UI logic to make the code easier to understand and maintain.
![Page 14: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/14.jpg)
Comparison
L - UI logicS - State of the UI
![Page 15: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/15.jpg)
Why Passive View?
Presentation Model and Supervising Controller are both reasonable alternatives. The strength that Passive View is that both of the alternatives require the view to do some of the synchronization work, which results in more untestable behavior.In Passive View, all the view update logic is placed in the presenter.
![Page 16: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/16.jpg)
How to create Passive View?
Separate the responsibilities for the visual display and the event handling behavior into different classes named, respectively, the view and the presenter. The view class manages the controls on the page. The presenter contains the logic to respond to the events, update the model (business logic and data of the application) and, in turn, manipulate the state of the view.
![Page 17: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/17.jpg)
Swiz Framework
![Page 18: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/18.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
![Page 19: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/19.jpg)
What Swiz Users are saying..
“Personally I think it is way better then Cairngorm!”
Kurt Wiersma, some Mach-ii dude
![Page 20: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/20.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!
![Page 21: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/21.jpg)
What is Swiz all about?
Let's Start..
![Page 22: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/22.jpg)
Swiz Overview
Flex Applications Require:Remote ServicesModels / DataControllers / LogicViews
![Page 23: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/23.jpg)
Swiz Overview
Components need each other
Wire ourselvesUse LocatorsVerbose XML
![Page 24: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/24.jpg)
Swiz Overview
Components need each other
Wire ourselvesUse LocatorsVerbose XMLIoCAnnotations
![Page 25: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/25.jpg)
Swiz Overview
Views communicate with components
Flex EventsMVC ParadigmDynamicMediatormakes it easy!
![Page 26: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/26.jpg)
Swiz OverviewApplications need remote data
Async TokensRespondersState around callsSwizRespondermakes it easy!
![Page 27: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/27.jpg)
Swiz Features
IoCinjects app
DynamicResponderremote data
DynamicMediatorevent handling
and a whole lot more...
![Page 28: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/28.jpg)
Swiz Doesn't mess with..
Excessive JEE patternsBoilerplate codeVerbose XML / MXML configurationOverly Prescriptive workflow
![Page 29: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/29.jpg)
IoC Recap..
Components require ‘dependencies’ to functionDependencies may be simple strings and values, or other componentsResolving complex dependencies is outside the scope of primary logic
![Page 30: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/30.jpg)
IoC with Swiz
Express dependencies through Metadata, or ‘Annotations’Swiz takes care of configuration through Dependency InjectionViews also have dependencies such as Models, or PresentationModelsSwiz handles everything for you!!
![Page 31: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/31.jpg)
Working with Swiz
Advanced Swiz
![Page 32: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/32.jpg)
Defining Beans
Define components in BeanLoadersWritten in plain old MXMLSwiz calls objects Beans because it only cares about their properties
![Page 33: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/33.jpg)
Defining BeanLoaders<BeanLoader xmlns=“org.swizframework.util.*”xmlns:mx=http://www.adobe.com/2006/mxml>
<mx:RemoteObject id=“userService”destination=“userService”/><mx:RemoteObject id=“mapService”destination=“mapService”/><controller:UserController id=“userController”/><controller:MapController id=“mapController”/></BeanLoader>
![Page 34: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/34.jpg)
Swiz's IoC Factory
When Swiz loads beans, it searches for ‘Inject’ metadataWhen objects are retrieved, Swiz performs the magic of InjectingSwiz adds event listeners for added to stage and removed from stage events Allows Swiz to Inject and clean up Views too!
![Page 35: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/35.jpg)
Loading Swiz
Use Swiz’s ConfigBean in MXMLRequires an array of BeanLoadersAccess to all configuration parameters
<swizframework:SwizConfig strict="true"beanLoaders="{[Beans]}"logEventLevel="{LogEventLevel.WARN}"/>
![Page 36: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/36.jpg)
Expressing Dependencies
Dependencies are NOT defined in MXML!Use [Inject] in your AS objectsSimilar to new Spring 2.0 configurationQualify bean to inject by id.
[Inject(bean="userController")] public var userController: UserController;
![Page 37: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/37.jpg)
Expressing Dependencies
To inject by type, forget the ‘bean’Swiz looks for bean which matches the variable typeWorks with interfaces and inheritanceSwiz throws ‘AmbiguousBean’ error if more than one bean could be injected
![Page 38: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/38.jpg)
View Autowiring
You can use Inject on accessors as well as propertiesProperties can be autowired with two way bindings!Accessors allow views to perform logic when dependencies are set
![Page 39: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/39.jpg)
Working with RemoteObjects
ServiceHelper bind result and fault handlers transparently Swiz offers simple methods for creating in AbstractController
![Page 40: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/40.jpg)
Dynamic MediatorsAdd [Mediate] annotation to a Controller function
[Mediate(event=“eventType”, properties=“foo, bar”)]public function doStuff(argA : String, argB : String) {}
Swiz creates a DynamicMediator for youAdds an eventListener for supplied type to Swiz’s centralDispatcherUses ‘properties’ to construct method call
![Page 41: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/41.jpg)
Recap
Swiz’s IoC is very easy to useSwiz provides a simple MVC paradigmVery little XML! Mostly AnnotationsSwiz provides core utilities for:
SwizResponders and ChainEventsEvent handlingDynamicMediators
![Page 42: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/42.jpg)
Recap
Swiz represents best practices learned from years of consultingSwiz is damn easy!New features are coming fast and furious!
![Page 43: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/43.jpg)
Swiz 1.0Module supportAny AS3 Project SupportAIR windows supportAdditional metadata:[PostConstruct], [PreDestroy]Custom metadata processors (might be THE killer feature of Swiz)
![Page 44: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/44.jpg)
Let's Start Coding...
![Page 45: Swiz DAO](https://reader034.vdocument.in/reader034/viewer/2022052523/555c23c5d8b42a09438b4b02/html5/thumbnails/45.jpg)
Resources
Swiz Resourceshttp://github.com/swiz/swiz-framework/http://groups.google.com/group/swiz-frameworkhttp://cdscott.blogspot.comhttp://soenkerohde.comhttp://www.returnundefined.com
Other Resourceshttp://github.com/nsdevaraj/SwizDAOhttp://code.google.com/p/dphibernatehttp://code.google.com/p/flex-mojoshttp://code.google.com/p/loom