45
by @ nsdevaraj

Swiz DAO

Embed Size (px)

Citation preview

Page 2: Swiz DAO

What we'll discussDI/ IoC IntroductionView PatternsWhat, Why, How

What is Swiz?Why should you use it?

Advanced SwizSwiz DAO

Page 3: Swiz DAO

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

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

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

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

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

View Patterns Hierarchy

Page 9: Swiz DAO

MVP PatternsPassive View Supervising Controller

Both variants allow you to increase the testability of your presentation logic.

Page 10: Swiz DAO

MVP Patterns

Passive View

Page 11: Swiz DAO

MVP Patterns

Supervising Controller

Page 12: Swiz DAO

Presentation Model

Page 13: Swiz DAO

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

Comparison

L - UI logicS - State of the UI

Page 15: Swiz DAO

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

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

Swiz Framework

Page 18: Swiz DAO

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

What Swiz Users are saying..

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

Kurt Wiersma, some Mach-ii dude

Page 20: Swiz DAO

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

What is Swiz all about?

Let's Start..

Page 22: Swiz DAO

Swiz Overview

Flex Applications Require:Remote ServicesModels / DataControllers / LogicViews

Page 23: Swiz DAO

Swiz Overview

Components need each other

Wire ourselvesUse LocatorsVerbose XML

Page 24: Swiz DAO

Swiz Overview

Components need each other

Wire ourselvesUse LocatorsVerbose XMLIoCAnnotations

Page 25: Swiz DAO

Swiz Overview

Views communicate with components

Flex EventsMVC ParadigmDynamicMediatormakes it easy!

Page 26: Swiz DAO

Swiz OverviewApplications need remote data

Async TokensRespondersState around callsSwizRespondermakes it easy!

Page 27: Swiz DAO

Swiz Features

IoCinjects app

DynamicResponderremote data

DynamicMediatorevent handling

and a whole lot more...

Page 28: Swiz DAO

Swiz Doesn't mess with..

Excessive JEE patternsBoilerplate codeVerbose XML / MXML configurationOverly Prescriptive workflow

Page 29: Swiz DAO

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

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

Working with Swiz

Advanced Swiz

Page 32: Swiz DAO

Defining Beans

Define components in BeanLoadersWritten in plain old MXMLSwiz calls objects Beans because it only cares about their properties

Page 33: Swiz DAO

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

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

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

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

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

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

Working with RemoteObjects

ServiceHelper bind result and fault handlers transparently Swiz offers simple methods for creating in AbstractController

Page 40: Swiz DAO

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

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

Recap

Swiz represents best practices learned from years of consultingSwiz is damn easy!New features are coming fast and furious!

Page 43: Swiz DAO

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

Let's Start Coding...

Page 45: Swiz DAO

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