Slideshare.net (beta)

 
Post to TwitterPost to Twitter
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons

All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 0 (more)

The Prana IoC Container

From herrodius, 7 months ago

Talk about the Prana IoC Container at the Adobe AIR Pre-Release to more

287 views  |  0 comments  |  0 favorites  |  9 downloads  |  1 embed (Stats)
 

Categories

Add Category
 
 

Groups / Events

 

 
Embed
options

More Info

This slideshow is Public
Total Views: 287
on Slideshare: 286
from embeds: 1

Slideshow transcript

Slide 1: Adobe Usergroup Belgium Christophe Herreman 26 january 2008 www.herrodius.com

Slide 2: What is Prana ? - An Inversion of Control (IoC) Container for ActionScript 3.0 - Based on Java Spring - Current release 0.4 (released today) - www.pranaframework.org

Slide 3: What is Prana ? - Cairngorm support - PureMVC support - Reflection API - Several Utilities

Slide 4: What is Inversion of Control ? Inversion of Control, also known as IOC, is an object-oriented programming principle that can be used to reduce coupling inherent in computer programs.

Slide 5: What is Inversion of Control ? Scenario: Class A uses class B to get something done Class A { public function doSomething():* { var b:B = new B(); var somethingDone:* = b.getSomethingDone(); return markAsDone(somethingDone); } } Notice : - can’t switch the implementation of B - can’t unit test in isolation

Slide 6: Types of Inversion of Control ? - Dependency Lookup - Dependency Pull - Contextualized Dependency Lookup - Dependency Injection - Constructor Injection - Setter Injection

Slide 7: Dependency Pull Class A { public function doSomething():* { var b:B = UberModel.getInstance().b; var somethingDone:* = b.getSomethingDone(); return markAsDone(somethingDone); } } UberModel.getInstance().b = new B(); var a:A = new A(); a.doSomething();

Slide 8: Contextualized Dependency Lookup Class A { public function doSomething(model:UberModel):* { var somethingDone:* = model.b.getSomethingDone(); return markAsDone(somethingDone); } } var model:UberModel = UberModel.getInstance(); var a:A = new A(); a.doSomething(model);

Slide 9: Constructor Injection Class A { public function A(b:B) { this.b = b; } public function doSomething():* { var somethingDone:* = b.getSomethingDone(); return markAsDone(somethingDone); } } var a:A = new A(new B()); a.doSomething();

Slide 10: Setter Injection Class A { private var b:B; public function set b(value:B):void { this.b = value; } public function doSomething():* { var somethingDone:* = b.getSomethingDone(); return markAsDone(somethingDone); } } var a:A = new A(); a.b = new B(); a.doSomething();

Slide 11: Inversion of Control? - Prefer setter injection - Type to interfaces !!! - Centralized configuration - Maintainability - Reusability - Testability - ... - Though counter-intuitive at first !

Slide 12: What is an IoC Container ? Creates and assembles components/objects and manages their lifecycle. Prana uses an XML dialect to define the “application context” (what objects are available and how they are related)

Slide 13: The Application Context // setter injection // constructor injection <objects> <objects> <object id=“a” class=“A”> <object id=“a” class=“A”> <property name=“b” ref=“b”/> <constructor-arg ref=“b”/> </object> </object> <object id=“b” class=“B”/> <object id=“b” class=“B”/> </objects> </objects>

Slide 14: Working with the IoC container <mx:Application xmlns:mx=\"http://www.adobe.com/2006/mxml\" creationComplete=\"onCreationComplete()“> ... private function onCreationComplete():void { _objectsLoader = new XmlObjectDefinitionsLoader(); _objectsLoader.addEventListener(ObjectDefinitionsLoaderEvent.COMPLETE, onObjectDefinitionsLoaderComplete); _objectsLoader.load(\"application-context.xml\"); } private function onObjectDefinitionsLoaderComplete(event:ObjectDefinitionsLoaderEvent):void { var container:ObjectContainer = _objectsLoader.container; var a:A = container.getObject(“a”); } ... </mx:Application>

Slide 15: Conclusion - Objects defined in external XML file - Loaded at runtime - Managed by container - Deploy your application with different configurations without recompiling!

Slide 16: Resources - www.pranaframework.org - www.herrodius.com

Slide 17: Questions?