SlideShare a Scribd company logo
1 of 49
Introduction to Swiz It’s easy. Seriously.No, I mean it. It is. 1 Nicholas Tunney
Session Goals What problems are we trying to solve? How do I set up Swiz? How do I put Swiz to work for me? Where else can I learn about Swiz? 2
What problems are we trying to solve? 3
Inversion of Control Decentralize application control Provide for actions on setup and teardown Separate the WHAT from the WHEN 4
Inversion of Control DANGER! 5 Courtesy of Joam Tall (Flickr)
Dependency Injection Objects are dependent on other objects Objects need those objects to be created (instantiated) to perform a task Objects that handle their own object creation are said to be ‘tightly coupled’ A simple change to the program results in major code changes, just not flexible Problem is best illustrated with an example 6
Dependency Injection public class Boat { private varengine:Engine= new Merc230(); 	public function boat () { } 	cruise (int RPM):String { engine.go(RPM); 	return engine.thrillFactor; } } 7
Dependency Injection public class Boat { private var_engine:Engine; 	public function boat () { } set Engine (engine:Engine):void { 		_engine = engine; } 	cruise (int RPM):String { 	_engine.go(RPM); 		return _engine.thrillFactor; } } 8
Dependency Injection myBoat:IBoat = new Boat(); myEngine:IEngine = new Merc230(); myBoat.setEngine(myEngine); myBoat.go(3000) // ‘w00t!’ myNewEngine:IEngine = new Merc57(); myBoat.go(3000) // ‘YEEEHHHHHAAAA!!!’ 9
Dependency Injection Can see how powerful dependency injection can be Can do that in various places across files (still lots of code to change, or via configuration using a framework like Swiz (one file to change) 10
Singletons Create once, use everywhere Low overhead, single instantiation Swiz is used to create these objects, and handle keeping state across the application 11
Creation of Transient Objects Swiz permits Prototyping objects Acts like an object factory Ask Swiz for an object, it injects dependencies and hands you a single instance of that object Not persistent 12
Event Handling We react to events in the application and perform tasks (WHAT versus WHEN) Event handling in Flex can be a nightmare challenge Events need to be dispatched from non-display objects to varied display objects Events need to be dispatched from display objects to non-display objects like controllers or their presentation models I want to fire an event ANYWHERE in my Flex application, and mediate it ANYWHERE in my Flex application 13
Interaction with External Services Every Flex app I have written (except 1) has interacted with external services, it’s the way of the web anymore Each external service call has a set signature and workflow Writing this workflow for every call is tedious, or moreover redundant 14
How do I set up Swiz? 15
Grab the SWC http://www.swizframework.org Place correct swc in /lib directory 16
SwizConfig Brutally simple, just like the framework Can simply copy/paste A few knobs to turn 17
SwizConfig <swiz:config>         <swiz:SwizConfig             setUpEventType="{ Event.ADDED_TO_STAGE }"             setUpEventPhase="{ EventPhase.CAPTURING_PHASE }"             setUpEventPriority="50"             tearDownEventType="{ Event.REMOVED_FROM_STAGE }"             tearDownEventPhase="{ EventPhase.CAPTURING_PHASE }"             tearDownEventPriority="50"             eventPackages="com.foo.event.*, org.bar.event.*"             viewPackages="com.foo.view.*, org.bar.view.*"             defaultFaultHandler="handleUnhandledFaults"             defaultDispatcher="global" />     </swiz:config> 18
SwizConfig <swiz:config>         <swiz:SwizConfig             eventPackages="com.foo.event.*, org.bar.event.*"             viewPackages="com.foo.view.*, org.bar.view.*” />     </swiz:config> 19
Logging Target I do not write perfect code, I need to log – a lot Built in logging for Swiz to console Can override and customize by extending the AbstractSwizLoggingTarget class     <swiz:loggingTargets>         <swiz:SwizTraceTarget id="myTraceTarget" />     </swiz:loggingTargets> 20
Stuff We Didn’t Do Verbose configuration Force the usage of J2EE patterns Have to define any special directory structure Tightly couple Swiz to our code (except with ServiceHelper and command chain) – no extending framework classes, etc) Take more than 5 minutes to review the Quickstart ;) 21
How do I put Swiz to work for me? 22
Review of Problems We Are Solving Inversion of Control Dependency Injection Singletons Creation of Transient Objects (Factory) Event Handling Interaction with External Services 23
Inversion of Control Permits us to define and declare dependencies: Controllers – for server interaction Model Delegates Services 24
Dependency Injection IoC container is defined by BeanProviders Define non-view classes Once defined, they can all be injected into your UI, presentation model, controllers, etc Can define in main application file, best practice to define and include <- but Swiz doesn’t try to force you to do this ;) - Use the <swiz:Bean /> tag 25
Dependency Injection Beans.mxml – or whatever you call it <swiz:BeanProvider     xmlns:swiz=" xmlns:service="org.swizframework.quickswiz.service.*"     xmlns:controller="org.swizframework.quickswiz.controller.*">       <service:UserService id="userService"/>     <controller:UserController id="userController"/>       <!-- We'll use the SwizServiceHelper to help simulate a server-side call. -->     <swiz:ServiceHelper id="serviceHelper" />   </swiz:BeanProvider> 26
Dependency Injection So how do we inject these objects? METADATA! 	(Note that Swiz can inject into public properties only) Inject by type (preferred) [Inject] variableName:Type Inject by name [Inject (“myService”)] variableName:RemoteObject; 27
Dependency Injection Can also inject a bean property 	[Inject (“ApplicationConfig.mode”)] currMode:String; Or provide a destination [Inject ( source=“ApplicationConfig.mode”,  	destination=“presentationModel.mode” ) ] 28
Dependency Injection Setter Injection is also possible [Inject] public function setModel (model:UserModel):void { 	… } 29
Singletons All objects created in the beans.mxmlas described are officially singletons This statement is not true for prototype objects BEAN LIFECYCLE 30
Bean LifeCycle [PostConstruct] [PreDestroy] 31
Creation of Transient Objects New object created for each request Much like an object factory Can send in properties via configuration as well <swiz:Prototype id=”User"     type="{ User }"     constructorArguments="{ someOtherBean }" /> 32
Event Handling Event mediation – decouples the WHAT from the WHEN Code the WHAT Wire the WHEN 33
Event Handling Two things we care about Dispatching events Mediating events 34
Event Handling Dispatching Events From a UIComponent dispatchEvent() important! The event must bubble! Swiz listens in the root container From other objects Inject a dispatcher [Dispatcher] Variable should have a type of IEventDispatcher Swiz handles the dependency injection 35
Event Handling Mediating Events Sooooooo easy! This was my aha moment for using a Flex framework 36
Event Handling Simple Event Mediation We can do this since we defined event packages Otherwise, specify fully qualified classname     [EventHandler( event=“EventClass.EVENT_CONSTANT” )]    public function myEventHandler (event:Event): void {        …    } 37
Event Handling Swiz inspects the handler and reacts accordingly (note there is no event property in this method)     [EventHandler( event=“EventClass.EVENT_CONSTANT” )]    public function myEventHandler (): void {        …    } 38
Event Handling Grab properties from the event (note that we can now explicitly call this method outside of an event)     [EventHandler( event=“MyEvent.EVENT”, properties=“user” )]    public function myEventHandler (user:User): void {        …    } 39
Event Handling Mediate multiple events with the same handler     [EventHandler( event=“MyEvent.EVENT”]     [EventHandler( event=“MyEvent.OTHER_EVENT”]     public function myEventHandler (): void {        …    } 40
Interaction with External Services Swiz provides beans for Async and other services Async: ServiceHelper Non Async: URLRequestHelper 41
Interaction with External Services ServiceHelper Define the bean Inject the bean Call the service Handle the results 42
Interaction with External Services Define the ServiceHelper bean 	<swiz:ServiceHelper id="serviceHelper" /> Inject the bean [Inject] 	public varsh:ServiceHelper; Call the service sh.executeServiceCall(ro.method(), resultHandler, faultHandler); 43
Demo Demonstrates everything we have talked about today, plus supports the Cat Internet meme. 44
Bonus: Client Persistence SharedObject- Provides methods for storing items <swiz:BeanProvider     xmlns:swiz="     xmlns:storage="org.swizframework.storage.*”>     <storage:SharedObjectBean id="soBean" /> </swiz:BeanProvider> 45
Bonus: Client Persistence Using the SharedObject bean [Inject] public varso:ISharedObjectBean;    [Bindable] public function get appIndex():int {     // the second parameter is the initial value     return so.getInt("appIndex", 0); }    public function set appIndex(index:int):void {     so.setInt("appIndex", index); } 46
Where else can I learn about Swiz? 47
Continued Learning http://swizframework.org Starting point for everything Wiki – everything in this preso is on the wiki Quickstart Configuration FAQ Everything else @swizframework Google Group –  groups.google.com/group/swiz-framework 48
49 Thanks! @ntunney blog.nictunney.com nic.tunney@nictunney.com bind53@gmail.com

More Related Content

What's hot

Introducing Vuex in your project
Introducing Vuex in your projectIntroducing Vuex in your project
Introducing Vuex in your projectDenny Biasiolli
 
Automated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xAutomated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xTatsuya Maki
 
Extending Kubernetes with Operators
Extending Kubernetes with OperatorsExtending Kubernetes with Operators
Extending Kubernetes with Operatorspeychevi
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developerEugene Zharkov
 
Tools & tricks for testing React applications
Tools & tricks for testing React applications Tools & tricks for testing React applications
Tools & tricks for testing React applications React London Community
 
The Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScriptThe Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScriptTim Perry
 
Introduction to React & Redux
Introduction to React & ReduxIntroduction to React & Redux
Introduction to React & ReduxBoris Dinkevich
 
Building a Single Page Application with VueJS
Building a Single Page Application with VueJSBuilding a Single Page Application with VueJS
Building a Single Page Application with VueJSdanpastori
 
(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer(Js) Export your own WebGL Viewer
(Js) Export your own WebGL ViewerJooinK
 
Taking Your GWT App to Tablets with GXT 4.0
Taking Your GWT App to Tablets with GXT 4.0Taking Your GWT App to Tablets with GXT 4.0
Taking Your GWT App to Tablets with GXT 4.0David Chandler
 
React Native Androidはなぜ動くのか
React Native Androidはなぜ動くのかReact Native Androidはなぜ動くのか
React Native Androidはなぜ動くのかYukiya Nakagawa
 
Session #8 adding magic to your app
Session #8  adding magic to your appSession #8  adding magic to your app
Session #8 adding magic to your appVitali Pekelis
 
ReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsRick Beerendonk
 
Better React state management with Redux
Better React state management with ReduxBetter React state management with Redux
Better React state management with ReduxMaurice De Beijer [MVP]
 
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...olrandir
 
Building Modern Web Applications using React and Redux
 Building Modern Web Applications using React and Redux Building Modern Web Applications using React and Redux
Building Modern Web Applications using React and ReduxMaxime Najim
 

What's hot (20)

React, Flux and a little bit of Redux
React, Flux and a little bit of ReduxReact, Flux and a little bit of Redux
React, Flux and a little bit of Redux
 
Workshop React.js
Workshop React.jsWorkshop React.js
Workshop React.js
 
Introducing Vuex in your project
Introducing Vuex in your projectIntroducing Vuex in your project
Introducing Vuex in your project
 
Automated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xAutomated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.x
 
Extending Kubernetes with Operators
Extending Kubernetes with OperatorsExtending Kubernetes with Operators
Extending Kubernetes with Operators
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 
Tools & tricks for testing React applications
Tools & tricks for testing React applications Tools & tricks for testing React applications
Tools & tricks for testing React applications
 
The Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScriptThe Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScript
 
React on es6+
React on es6+React on es6+
React on es6+
 
Introduction to React & Redux
Introduction to React & ReduxIntroduction to React & Redux
Introduction to React & Redux
 
Building a Single Page Application with VueJS
Building a Single Page Application with VueJSBuilding a Single Page Application with VueJS
Building a Single Page Application with VueJS
 
(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer(Js) Export your own WebGL Viewer
(Js) Export your own WebGL Viewer
 
Taking Your GWT App to Tablets with GXT 4.0
Taking Your GWT App to Tablets with GXT 4.0Taking Your GWT App to Tablets with GXT 4.0
Taking Your GWT App to Tablets with GXT 4.0
 
React Native Androidはなぜ動くのか
React Native Androidはなぜ動くのかReact Native Androidはなぜ動くのか
React Native Androidはなぜ動くのか
 
Session #8 adding magic to your app
Session #8  adding magic to your appSession #8  adding magic to your app
Session #8 adding magic to your app
 
ReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page ApplicationsReactJS.NET - Fast and Scalable Single Page Applications
ReactJS.NET - Fast and Scalable Single Page Applications
 
Better React state management with Redux
Better React state management with ReduxBetter React state management with Redux
Better React state management with Redux
 
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
Android: the Single Activity, Multiple Fragments pattern | One Activity to ru...
 
Building Modern Web Applications using React and Redux
 Building Modern Web Applications using React and Redux Building Modern Web Applications using React and Redux
Building Modern Web Applications using React and Redux
 

Viewers also liked

Agile: I think a Chicken just ate my Pig
Agile: I think a Chicken just ate my PigAgile: I think a Chicken just ate my Pig
Agile: I think a Chicken just ate my Pigntunney
 
Free Range Chickens and Other Agile Habitats
Free Range Chickens and Other Agile HabitatsFree Range Chickens and Other Agile Habitats
Free Range Chickens and Other Agile HabitatsMatt Phillips
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...Brian Solis
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)maditabalnco
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 

Viewers also liked (6)

Agile: I think a Chicken just ate my Pig
Agile: I think a Chicken just ate my PigAgile: I think a Chicken just ate my Pig
Agile: I think a Chicken just ate my Pig
 
Free Range Chickens and Other Agile Habitats
Free Range Chickens and Other Agile HabitatsFree Range Chickens and Other Agile Habitats
Free Range Chickens and Other Agile Habitats
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 

Similar to Introduction to Swiz - Dependency Injection, IoC and Event Handling

Delegateless Coordinator
Delegateless CoordinatorDelegateless Coordinator
Delegateless CoordinatorTales Andrade
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinBarry Gervin
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009Jonas Follesø
 
Delegateless Coordinators - take 2
Delegateless Coordinators - take 2Delegateless Coordinators - take 2
Delegateless Coordinators - take 2Tales Andrade
 
Introduction to Google Guice
Introduction to Google GuiceIntroduction to Google Guice
Introduction to Google GuiceKnoldus Inc.
 
Application Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The UglyApplication Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The UglyRichard Lord
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Androidma-polimi
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIVisual Engineering
 
Ios development 2
Ios development 2Ios development 2
Ios development 2elnaqah
 
Whirlwind tour of activiti 7
Whirlwind tour of activiti 7Whirlwind tour of activiti 7
Whirlwind tour of activiti 7Ryan Dawson
 
Android应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介easychen
 
2011 py con
2011 py con2011 py con
2011 py conEing Ong
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonfNataliya Patsovska
 
DEFCON 18- These Aren't the Permissions You're Looking For
DEFCON 18- These Aren't the Permissions You're Looking ForDEFCON 18- These Aren't the Permissions You're Looking For
DEFCON 18- These Aren't the Permissions You're Looking ForMichael Scovetta
 

Similar to Introduction to Swiz - Dependency Injection, IoC and Event Handling (20)

Swiz DAO
Swiz DAOSwiz DAO
Swiz DAO
 
Delegateless Coordinator
Delegateless CoordinatorDelegateless Coordinator
Delegateless Coordinator
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
Android101
Android101Android101
Android101
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009
 
Delegateless Coordinators - take 2
Delegateless Coordinators - take 2Delegateless Coordinators - take 2
Delegateless Coordinators - take 2
 
Introduction to Google Guice
Introduction to Google GuiceIntroduction to Google Guice
Introduction to Google Guice
 
Application Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The UglyApplication Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The Ugly
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Ios development 2
Ios development 2Ios development 2
Ios development 2
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
Wwf
WwfWwf
Wwf
 
Whirlwind tour of Activiti 7 by Ryan Dawson
Whirlwind tour of Activiti 7 by Ryan DawsonWhirlwind tour of Activiti 7 by Ryan Dawson
Whirlwind tour of Activiti 7 by Ryan Dawson
 
Whirlwind tour of activiti 7
Whirlwind tour of activiti 7Whirlwind tour of activiti 7
Whirlwind tour of activiti 7
 
Android应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介
 
2011 py con
2011 py con2011 py con
2011 py con
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
 
DEFCON 18- These Aren't the Permissions You're Looking For
DEFCON 18- These Aren't the Permissions You're Looking ForDEFCON 18- These Aren't the Permissions You're Looking For
DEFCON 18- These Aren't the Permissions You're Looking For
 

Recently uploaded

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Introduction to Swiz - Dependency Injection, IoC and Event Handling

  • 1. Introduction to Swiz It’s easy. Seriously.No, I mean it. It is. 1 Nicholas Tunney
  • 2. Session Goals What problems are we trying to solve? How do I set up Swiz? How do I put Swiz to work for me? Where else can I learn about Swiz? 2
  • 3. What problems are we trying to solve? 3
  • 4. Inversion of Control Decentralize application control Provide for actions on setup and teardown Separate the WHAT from the WHEN 4
  • 5. Inversion of Control DANGER! 5 Courtesy of Joam Tall (Flickr)
  • 6. Dependency Injection Objects are dependent on other objects Objects need those objects to be created (instantiated) to perform a task Objects that handle their own object creation are said to be ‘tightly coupled’ A simple change to the program results in major code changes, just not flexible Problem is best illustrated with an example 6
  • 7. Dependency Injection public class Boat { private varengine:Engine= new Merc230(); public function boat () { } cruise (int RPM):String { engine.go(RPM); return engine.thrillFactor; } } 7
  • 8. Dependency Injection public class Boat { private var_engine:Engine; public function boat () { } set Engine (engine:Engine):void { _engine = engine; } cruise (int RPM):String { _engine.go(RPM); return _engine.thrillFactor; } } 8
  • 9. Dependency Injection myBoat:IBoat = new Boat(); myEngine:IEngine = new Merc230(); myBoat.setEngine(myEngine); myBoat.go(3000) // ‘w00t!’ myNewEngine:IEngine = new Merc57(); myBoat.go(3000) // ‘YEEEHHHHHAAAA!!!’ 9
  • 10. Dependency Injection Can see how powerful dependency injection can be Can do that in various places across files (still lots of code to change, or via configuration using a framework like Swiz (one file to change) 10
  • 11. Singletons Create once, use everywhere Low overhead, single instantiation Swiz is used to create these objects, and handle keeping state across the application 11
  • 12. Creation of Transient Objects Swiz permits Prototyping objects Acts like an object factory Ask Swiz for an object, it injects dependencies and hands you a single instance of that object Not persistent 12
  • 13. Event Handling We react to events in the application and perform tasks (WHAT versus WHEN) Event handling in Flex can be a nightmare challenge Events need to be dispatched from non-display objects to varied display objects Events need to be dispatched from display objects to non-display objects like controllers or their presentation models I want to fire an event ANYWHERE in my Flex application, and mediate it ANYWHERE in my Flex application 13
  • 14. Interaction with External Services Every Flex app I have written (except 1) has interacted with external services, it’s the way of the web anymore Each external service call has a set signature and workflow Writing this workflow for every call is tedious, or moreover redundant 14
  • 15. How do I set up Swiz? 15
  • 16. Grab the SWC http://www.swizframework.org Place correct swc in /lib directory 16
  • 17. SwizConfig Brutally simple, just like the framework Can simply copy/paste A few knobs to turn 17
  • 18. SwizConfig <swiz:config>         <swiz:SwizConfig             setUpEventType="{ Event.ADDED_TO_STAGE }"             setUpEventPhase="{ EventPhase.CAPTURING_PHASE }"             setUpEventPriority="50"             tearDownEventType="{ Event.REMOVED_FROM_STAGE }"             tearDownEventPhase="{ EventPhase.CAPTURING_PHASE }"             tearDownEventPriority="50"             eventPackages="com.foo.event.*, org.bar.event.*"             viewPackages="com.foo.view.*, org.bar.view.*"             defaultFaultHandler="handleUnhandledFaults"             defaultDispatcher="global" />     </swiz:config> 18
  • 19. SwizConfig <swiz:config>         <swiz:SwizConfig             eventPackages="com.foo.event.*, org.bar.event.*"             viewPackages="com.foo.view.*, org.bar.view.*” />     </swiz:config> 19
  • 20. Logging Target I do not write perfect code, I need to log – a lot Built in logging for Swiz to console Can override and customize by extending the AbstractSwizLoggingTarget class <swiz:loggingTargets>      <swiz:SwizTraceTarget id="myTraceTarget" /> </swiz:loggingTargets> 20
  • 21. Stuff We Didn’t Do Verbose configuration Force the usage of J2EE patterns Have to define any special directory structure Tightly couple Swiz to our code (except with ServiceHelper and command chain) – no extending framework classes, etc) Take more than 5 minutes to review the Quickstart ;) 21
  • 22. How do I put Swiz to work for me? 22
  • 23. Review of Problems We Are Solving Inversion of Control Dependency Injection Singletons Creation of Transient Objects (Factory) Event Handling Interaction with External Services 23
  • 24. Inversion of Control Permits us to define and declare dependencies: Controllers – for server interaction Model Delegates Services 24
  • 25. Dependency Injection IoC container is defined by BeanProviders Define non-view classes Once defined, they can all be injected into your UI, presentation model, controllers, etc Can define in main application file, best practice to define and include <- but Swiz doesn’t try to force you to do this ;) - Use the <swiz:Bean /> tag 25
  • 26. Dependency Injection Beans.mxml – or whatever you call it <swiz:BeanProvider     xmlns:swiz=" xmlns:service="org.swizframework.quickswiz.service.*"     xmlns:controller="org.swizframework.quickswiz.controller.*">       <service:UserService id="userService"/>     <controller:UserController id="userController"/>       <!-- We'll use the SwizServiceHelper to help simulate a server-side call. -->     <swiz:ServiceHelper id="serviceHelper" />   </swiz:BeanProvider> 26
  • 27. Dependency Injection So how do we inject these objects? METADATA! (Note that Swiz can inject into public properties only) Inject by type (preferred) [Inject] variableName:Type Inject by name [Inject (“myService”)] variableName:RemoteObject; 27
  • 28. Dependency Injection Can also inject a bean property [Inject (“ApplicationConfig.mode”)] currMode:String; Or provide a destination [Inject ( source=“ApplicationConfig.mode”, destination=“presentationModel.mode” ) ] 28
  • 29. Dependency Injection Setter Injection is also possible [Inject] public function setModel (model:UserModel):void { … } 29
  • 30. Singletons All objects created in the beans.mxmlas described are officially singletons This statement is not true for prototype objects BEAN LIFECYCLE 30
  • 32. Creation of Transient Objects New object created for each request Much like an object factory Can send in properties via configuration as well <swiz:Prototype id=”User"     type="{ User }"     constructorArguments="{ someOtherBean }" /> 32
  • 33. Event Handling Event mediation – decouples the WHAT from the WHEN Code the WHAT Wire the WHEN 33
  • 34. Event Handling Two things we care about Dispatching events Mediating events 34
  • 35. Event Handling Dispatching Events From a UIComponent dispatchEvent() important! The event must bubble! Swiz listens in the root container From other objects Inject a dispatcher [Dispatcher] Variable should have a type of IEventDispatcher Swiz handles the dependency injection 35
  • 36. Event Handling Mediating Events Sooooooo easy! This was my aha moment for using a Flex framework 36
  • 37. Event Handling Simple Event Mediation We can do this since we defined event packages Otherwise, specify fully qualified classname [EventHandler( event=“EventClass.EVENT_CONSTANT” )] public function myEventHandler (event:Event): void { … } 37
  • 38. Event Handling Swiz inspects the handler and reacts accordingly (note there is no event property in this method) [EventHandler( event=“EventClass.EVENT_CONSTANT” )] public function myEventHandler (): void { … } 38
  • 39. Event Handling Grab properties from the event (note that we can now explicitly call this method outside of an event) [EventHandler( event=“MyEvent.EVENT”, properties=“user” )] public function myEventHandler (user:User): void { … } 39
  • 40. Event Handling Mediate multiple events with the same handler [EventHandler( event=“MyEvent.EVENT”] [EventHandler( event=“MyEvent.OTHER_EVENT”] public function myEventHandler (): void { … } 40
  • 41. Interaction with External Services Swiz provides beans for Async and other services Async: ServiceHelper Non Async: URLRequestHelper 41
  • 42. Interaction with External Services ServiceHelper Define the bean Inject the bean Call the service Handle the results 42
  • 43. Interaction with External Services Define the ServiceHelper bean <swiz:ServiceHelper id="serviceHelper" /> Inject the bean [Inject] public varsh:ServiceHelper; Call the service sh.executeServiceCall(ro.method(), resultHandler, faultHandler); 43
  • 44. Demo Demonstrates everything we have talked about today, plus supports the Cat Internet meme. 44
  • 45. Bonus: Client Persistence SharedObject- Provides methods for storing items <swiz:BeanProvider     xmlns:swiz="     xmlns:storage="org.swizframework.storage.*”>     <storage:SharedObjectBean id="soBean" /> </swiz:BeanProvider> 45
  • 46. Bonus: Client Persistence Using the SharedObject bean [Inject] public varso:ISharedObjectBean;    [Bindable] public function get appIndex():int {     // the second parameter is the initial value     return so.getInt("appIndex", 0); }    public function set appIndex(index:int):void {     so.setInt("appIndex", index); } 46
  • 47. Where else can I learn about Swiz? 47
  • 48. Continued Learning http://swizframework.org Starting point for everything Wiki – everything in this preso is on the wiki Quickstart Configuration FAQ Everything else @swizframework Google Group – groups.google.com/group/swiz-framework 48
  • 49. 49 Thanks! @ntunney blog.nictunney.com nic.tunney@nictunney.com bind53@gmail.com

Editor's Notes

  1. Hard to define - goal is to decentralize to promote reusability and maintainabilityWHAT being - what actions i need to perform, what screens I need to showWHEN being - well, when I need to do those things
  2. Any time we decentralize control, this means that we need to add configuration – they go hand in hand
  3. Dependent on things like children an employee has a car, it drives() him to workEmployee needs to get to work, well, the car knows how to drive him, the employee doesn’tIf the employee object creates the car, it means we are stuck with that car every time we create the employeeWhat if we want a different car, or even a bike!
  4. Boat has a merc 230Every time we ask for a boat, we get a boat with a merc 230When we ask the boat to cruise, it does so by using its engine
  5. Now, what if we instead pass the engine in? We can pass in any engine as long as it extends the engine class, or even better, implements Iengine, and hence has the go() functionNow if I want a larger engine, I pass it in at runtime
  6. See difference in go() with the thrill factor
  7. Swiz helps us to manage DI by handling the configuration and injectionMuch like an object factory
  8. Everywhere I ask for a BoatService,swiz will pass in the same BoatService
  9. Created on the fly
  10. See difference in zip files for flex 3 and 4
  11. Holy crap!
  12. Ok, that’s better
  13. Verbose logging, can see what has been injected, what event will be mediated, etc
  14. J2ee – use command pattern instead of controllerWe can replace our metadata and automatic classes with our own classes and the program will continue running – no framework classes to extendEverything in this preso is in the quickstart, and in the docs, which are SHORT
  15. If it can&apos;t find the described event, Swiz will actually generate the code for an Event that will fit the need and spit it out in the console for you to copy and paste if you wanttwo, Flash event handling is all string based, meaning MyEvent.FOO is actually just a string value, &quot;myEventType&quot; or whateverwhich can cause collisions if two events have the same literal string value for the typeSwiz doesn&apos;t use the string valuesit actually matches up the event class and the constant to figure out which event handlers to invokeso the event type string collision issue is eliminated
  16. Since there is no event property, we can actually explicitly call myEventHandler() from other places
  17. Properties that would come on the event as the result get pulled off and handed off as arguments
  18. Same method can interpret multiple events – no limit
  19. 2 different helpersCalls that return an async token like flash remoting- Calls that do not return an async token, like requesting an image from a URL
  20. Sometimes we need to store variables on the client side, like a user object or some other object we need to maintain state
  21. setValue, setNumber, setBoolean, setString, etc