swiz dao

Post on 20-May-2015

1.651 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

What is Swiz?Why should you use it?

Advanced SwizSwiz 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

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.

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".

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.

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.

View Patterns Hierarchy

MVP PatternsPassive View Supervising Controller

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

MVP Patterns

Passive View

MVP Patterns

Supervising Controller

Presentation Model

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.

Comparison

L - UI logicS - State of the UI

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.

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.

Swiz Framework

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 saying..

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

Kurt Wiersma, some Mach-ii dude

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!

What is Swiz all about?

Let's Start..

Swiz Overview

Flex Applications Require:Remote ServicesModels / DataControllers / LogicViews

Swiz Overview

Components need each other

Wire ourselvesUse LocatorsVerbose XML

Swiz Overview

Components need each other

Wire ourselvesUse LocatorsVerbose XMLIoCAnnotations

Swiz Overview

Views communicate with components

Flex EventsMVC ParadigmDynamicMediatormakes it easy!

Swiz OverviewApplications need remote data

Async TokensRespondersState around callsSwizRespondermakes it easy!

Swiz Features

IoCinjects app

DynamicResponderremote data

DynamicMediatorevent handling

and a whole lot more...

Swiz Doesn't mess with..

Excessive JEE patternsBoilerplate codeVerbose XML / MXML configurationOverly Prescriptive workflow

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

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!!

Working with Swiz

Advanced Swiz

Defining Beans

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

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>

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!

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}"/>

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;

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

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

Working with RemoteObjects

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

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

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

Recap

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

Swiz 1.0Module supportAny AS3 Project SupportAIR windows supportAdditional metadata:[PostConstruct], [PreDestroy]Custom metadata processors (might be THE killer feature of Swiz)

Let's Start Coding...

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

top related