Introduction

Articles covering the latest in the developer world, tutorials on my new projects, elegant solutions to common programming problems and visionary thoughts on programming.

May 19th, 2006

Dependency Injection

cheap cialis pill certified cialis cheap viagra in canada cialis buy drug buy generic cialis viagra buy 25mg viagra cheap viagra without prescription buy cheapest viagra on line purchase viagra cialis 10mg buying generic viagra cialis pills viagra from india cheapest sildenafil citrate cheap cialis no rx viagra india cialis bangkok viagra for order buy sildenafil internet buy generic viagra online buying cialis online where to order cialis tablet cialis find cialis no prescription required viagra cheap drug order cialis cheap online online pharmacy cialis cialis no rx order generic cialis price of cialis viagra soft drug viagra cheap viagra from uk order cialis no prescription order cheap viagra viagra drug order cheap cialis cheap cialis pharmacy best price for viagra cheap viagra from usa cost cialis cialis overnight shipping cheapest generic cialis online generic viagra online online viagra viagra sales cheap cialis in canada compare cialis prices online cialis online drug viagra online purchase discount cialis without prescription no rx viagra cialis overnight viagra uk cialis order cheap cialis from usa buying cialis cialis overnight delivery cialis in bangkok buy and purchase sildenafil online impotence treatment cheap price viagra viagra sale cheap cialis tablet drug cialis generic cialis online cheap viagra pharmacy find discount cialis online viagra malaysia cialis without a prescription buy cialis online cheap viagra rx buy no rx viagra cialis 20mg viagra in malaysia discount viagra online buy sildenafil cheap buy viagra low price buy cialis cialis cheap price cialis cheap generic viagra cialis canada low cost viagra buy cheap viagra cialis vs viagra order cialis from us cialis tablets find no rx cialis buy generic cialis online buy viagra overnight delivery cheapest cialis price buy cheapest cialis on line order cialis in canada viagra tablet viagra no online prescription find cheap cialis online viagra price order viagra no prescription cheap generic cialis buy viagra online cheap cialis uk cialis without rx generic cialis cheap viagra vs cialis order cialis on internet viagra tablets viagra purchase impotence drugs buy cialis generic cialis tablet cialis cheapest price order viagra from canada viagra generic cheap viagra from canada order cialis compare viagra prices online find cheap cialis impotence cure pfizer viagra find discount cialis cheapest cialis buy cialis from india impotence buy cheapest viagra online cialis side effects viagra order discount cialis online cialis in malaysia cialis in uk viagra in uk cialis online without prescription cialis online pharmacy order viagra buy viagra online viagra side effects cialis sale discount cialis no rx cheapest viagra find cialis order cialis no rx buy cialis low price buy viagra cheap drug cialis online purchase order discount viagra online 50 mg viagra 100 mg viagra 10mg cialis cost of cialis cheapest cialis prices buy discount viagra online cialis sales 50mg viagra cialis price buy viagra on internet cialis pill cheapest cialis online purchase viagra overnight delivery cheap cialis from canada cheapest viagra price cialis 20 mg buy sildenafil low cost order viagra without prescription buy viagra lowest price no prescription cialis order viagra on internet discount cialis overnight delivery cialis cheap drug viagra approved viagra no rx required compare viagra prices no rx cialis cheap cialis on internet buy viagra from india buy discount cialis online viagra pharmacy online order viagra from us cialis free delivery cialis for order buy cialis from canada viagra without rx viagra online review 10 mg cialis cheap viagra no rx cheapest viagra prices viagra prices cialis pharmacy order no rx cialis buy cialis in us buy cialis no prescription required order cialis from canada lowest price cialis cheap cialis internet online pharmacy viagra cheapest generic cialis generic drugs cialis india find cialis without prescription best price cialis buy viagra without prescription cheap cialis in uk where to buy viagra 20 mg cialis cheap cialis from uk buy sildenafil canada cialis no rx required cialis in us buy cialis overnight delivery cialis cheap price order cheap viagra online 20mg cialis buy cheap viagra online viagra internet viagra without prescription free cialis buy cialis us cialis buy buy viagra in canada order viagra cheap online find viagra without prescription viagra pills cheap cialis no prescription viagra online without prescription order generic viagra cialis discount viagra cheapest price purchase viagra no rx viagra no rx viagra cheap discount viagra overnight delivery sale cialis cialis pharmacy online purchase cialis without prescription pharmacy online cialis medication discount viagra buy cheap cialis impotence medication viagra medication find cialis on internet impotence pills cialis prices discount viagra without prescription cialis online cheap cialis online review find cheap viagra online buy viagra us purchase cialis online certified viagra where to order viagra buy cheapest viagra buy cialis internet order cialis online buy sildenafil online buy cialis cheap cheap viagra purchase cialis find discount viagra buy cialis on internet cialis buy online buy sildenafil online without a prescription viagra buy online order cheap cialis online viagra information no prescription viagra cost of viagra buy cialis in canada buy cialis online buy viagra cheapest generic viagra cialis us cialis australia fda approved cialis lowest price for viagra viagra bangkok cialis prescription cialis cost buy no rx cialis buy viagra internet viagra discount order viagra overnight delivery generic cialis viagra australia 25 mg viagra order viagra online viagra overnight cialis rx order cialis in us order viagra no rx order discount cialis online viagra vendors order viagra in us buy sildenafil in uk viagra us buy generic viagra viagra canada viagra no prescription viagra cheap price cheap viagra tablet viagra free delivery overnight viagra purchase viagra online find cheap viagra cialis malaysia best price viagra cialis free sample find viagra on internet cialis generic buy sildenafil in canada order cialis no prescription required cheapest viagra online purchase cialis no rx viagra in us order discount cialis cheap viagra internet free viagra cialis approved best price for cialis cialis from india find no rx viagra generic viagra viagra from canada viagra online pharmacy buy viagra from canada cheapest generic viagra online buy cheapest cialis discount cialis viagra overnight delivery cialis without prescription 100mg viagra cialis in australia price of viagra order cialis overnight delivery cheap viagra in uk buying generic cialis viagra pill buy cialis on line low cost cialis find discount viagra online buying viagra cheap cialis overnight delivery pharmacy cialis cheap viagra pill viagra prescription find viagra online buy cialis lowest price discount viagra no rx online cialis viagra free sample cheap viagra in usa find viagra cheap viagra online buy viagra no rx generic viagra cheap buy cialis without prescription buy viagra in us cheap viagra overnight delivery cheap cialis in usa cheap cialis online viagra order no rx viagra viagra soft tab find cialis online lowest price viagra cialis drug cialis vendors viagra online stores erectile dysfunction order viagra in canada buy viagra on line viagra overnight shipping viagra online cheap lowest price for cialis approved viagra pharmacy cialis 10 mg cialis no online prescription cialis purchase cialis from canada order cialis without prescription viagra for sale viagra in australia approved cialis pharmacy buy viagra generic buy sildenafil in spain find viagra no prescription required cialis no prescription buy viagra from us order viagra no prescription required cost viagra purchase viagra without prescription buy cialis no rx cialis cheap cialis internet tablet viagra cheap viagra on internet viagra cost pharmacy viagra cialis soft tab cialis information buy cheap cialis internet purchase cialis overnight delivery cheap cialis without prescription buy viagra no prescription required compare cialis prices buy cheap cialis online overnight cialis where to buy cialis cheap cialis buy cheap viagra internet buy discount cialis viagra buy drug cheap viagra no prescription buy sildenafil citrate buying viagra online buy discount viagra fda approved viagra cialis online stores cheap cialis tablets buy cheapest cialis online cheap viagra tablets order discount viagra sale viagra viagra online cialis for sale cialis soft viagra pharmacy buy cialis from us viagra without a prescription viagra in bangkok

Applications consist of multiple classes which collaborate with each other. For example an instance of class A needs an instance of class B and C to do its job; in other words, class A depends on class B and C; class B and C are thus dependencies of class A.

There are three options to satisfy dependencies:

  1. hard-code dependencies,
  2. look up dependencies,
  3. use the Dependency Injection pattern.

1. Hard-coding dependencies is the easiest strategy: class A simply instantiates its dependencies.

  1. class A {
  2.    
  3.     private var b:B;
  4.     private var c:C;
  5.    
  6.     public function A() {
  7.         b = new B(3, true);
  8.         c = new C();
  9.     }
  10.    
  11.     public function doSomething() {
  12.         var r:String = b.doSomething();
  13.         c.doSomething(r);
  14.     }
  15.    
  16. }

Problems of hard-coding dependencies:

  • Configuration is distributed across the whole application (configuration is in this case wiring up the instances and configuring dependent instances).
  • Class A must be modified to exchange a dependency (tight coupling): the instance of B may be replaced by an instance of SubB which fulfils the same contract as its super-class B. If B were an interface than any implementations could be used to satisfy the dependency.
  • What if a fourth class D has a dependency to the same instance of B as class A?

2. Looking up dependencies requires a context: class A gets the context and looks up its dependencies.

  1. class A {
  2.    
  3.     private var b:B;
  4.     private var c:C;
  5.    
  6.     public function A() {
  7.         var context:Context = Context.getInstance();
  8.         b = context.getB();
  9.         c = context.getC();
  10.     }
  11.    
  12.     …
  13.    
  14. }

Advantages of looking up dependencies:

  • Partially centralized configuration of the context: dependency b is already fully configured; but every instance looks up its dependencies on its own.
  • One instance can be used to satisfy multiple dependencies: an instance of class D can simply use context.getB() to get the same instance.

Problems of looking up dependencies:

  • Class A depends on a context: makes unit testing more difficult and the look ups are disturbing.
  • Code is bloated with dependency look-ups.

3. Using the Dependency Injection pattern is simple and places no requirements: class A provides ways to inject dependencies.

Advantages of dependency injection:

  • Configuration is centralized in one place: both configuration of instances and wiring up instances.
  • Dependencies can be exchanged easily (loose coupling).
  • Wiring up instances is made easy.

Problem of dependency injection: The wiring code may become rather complex if there are a lot of instances with a lot of dependencies to satisfy.

One way to go is to use Constructor Injection. In this approach class A declares a constructor with paramters for both dependencies; the dependencies are given on instantiation.

  1. class A {
  2.    
  3.     private var b:B;
  4.     private var c:C;
  5.    
  6.     public function A(b:B, c:C) {
  7.         this.b = b;
  8.         this.c = c;
  9.     }
  10.    
  11.     …
  12.    
  13. }

Advantages of constructor injection:

  • Dependencies cannot be changed after instantiation.
  • Initialization which requires all dependencies can be done directly in the constructor.
  • Instance is not in illegal state after instantiation.

Problems of constructor injection:

  • Parameter list of constructor may become very long (there may be a lot of dependencies, plus other information to pass to the constructor).
  • Parameters are distinguished by index and not by name, which may make the code harder to understand.

Another way to go is Setter Injection. In this approach class A provides setters for both dependencies; the dependencies are satisfied after instantiation.

  1. class A {
  2.    
  3.     private var b:B;
  4.     private var c:C;
  5.    
  6.     public function A() {
  7.     }
  8.    
  9.     public function setB(b:B):Void {
  10.         this.b = b;
  11.     }
  12.    
  13.     public function setC(c:C):Void {
  14.         this.c = c;
  15.     }
  16.    
  17.     …
  18.    
  19. }

Advantages of setter injection:

  • Constructor can be used to pass other information than dependencies.
  • Code is easier to understand because names rather than indices are used to distinguish dependencies.

Problems of setter injection:

  • Dependencies may not have been satisfied when needed.
  • Dependencies may be changed after ‘official’ initialization.
  • Initialization may have to be done after all dependencies are satisfied: init-method is needed.

While dependency injection is a pattern with many advantages, there are also some problems when used extensively, which can only be solved by an Inversion of Control Container. Such a container provides means of managing instances: lifecycle management (instantiating classes, setting dependencies, invoking init-methods, destroying classes), looking up managed instances, configuring managed instances, resolving dependencies.

In my following articles I’m going to present the As2lib Inversion of Control Container and show you how it solves the problems mentioned above and which other functionalities it provides (for example using its generic XML dialect to create UIs with ActionStep, AsWing, EnFlash or any other component library).

Further Reading: Inversion of Control Containers and the Dependency Injection pattern

March 5th, 2006

As2ant 1.5: Specify Swfmill XML within Task

You can now specify the swfmill xml directly in the task. The advantages are that you have only one file to maintain (build.xml) and that you can use ant properties within the swfmill xml.

  1. <swf src="${src.dir}/com/simonwacker/ant/Sample.as" dest="${build.dir}/sample.swf">
  2.   <xml>
  3.     <![CDATA[
  4.       <movie width="300" height="100" framerate="31">
  5.         <background color=’#FF8A00′/>
  6.         <frame>
  7.           <library>
  8.             <clip id="simonwacker" import="${res}/simonwacker.jpg"/>
  9.             <font id="pixel" import="${res}/pixel.ttf"/>
  10.           </library>
  11.         </frame>
  12.       </movie>
  13.     ]]>
  14.   </xml>
  15. </swf>

Further enhancements are:

[+] org.as2lib.ant.Mtasc
Added special XML support for As2lib Bean Factory and Context.

[+] org.as2lib.ant.Swfmill / org.as2lib.ant.Swf
Added support for specifying the swfmill xml directly in the tasks.

[+] org.as2lib.ant.Swf
Added support for overriding font family names.

[+] org.as2lib.ant.Swfmill / org.as2lib.ant.Swf
Added support for extra verbose debugging output.

Download As2ant 1.5 from sourceforge.net
Download As2ant 1.5 from simonwacker.com

I hope you enjoy the new features!

February 27th, 2006

As2ant 1.0 with As2api Task

As2ant 1.0 has just been released! Best new features are the new As2api task and the custom-arguments support for the Mtasc task.

Full list of changes:

[+] org.as2lib.ant.As2api
Added support for HTML API documentation generation via As2api.

[!] org.as2lib.ant.Mtasc
Fixed bug with package-argument: Use relative paths!

[+] org.as2lib.ant.Mtasc
Added support for custom arguments: <argument name=”-myargument” value=”myvalue”/>

[~] org.as2lib.ant.Mtasc
Ignore classes in source xml files that cannot be found.

[+] org.as2lib.ant.Mtasc
Added support for source xml files with ‘type’ as attribute.

[+] org.as2lib.ant.Mtasc
Improved commandline output by adding locations to all exceptions.

[~] org.as2lib.ant.Mtasc
Compile all source files in split-mode, even when one raises a compile error.

Download As2ant 1.0 from sourceforge.net
Downlaod As2ant 1.0 from simonwacker.com

If you find any bugs please report them!

October 13th, 2005

As2lib 0.9.3, New Version

A new version of the as2lib is finally available for download.

Major changes are:

  • A completely rewritten File framework that offers various file format representations, like properties files, and support for loading and parsing these files - org.as2lib.io.file
  • Support for configuring the Logging framework via XML - org.as2lib.env.log.parser
  • Improved Process and Unit Testing frameworks - org.as2lib.app.exec, org.as2lib.test.unit
  • Many bug fixes in the AOP framework - org.as2lib.aop
  • New Regular Expression (RegExp) framework (note that there is still much documentation missing) - org.as2lib.regexp

As you can see, it is definitely worth updating to this new version.

Download As2lib 0.9.3.

View API Documentation

If you find any bugs, report it, if you want a new feature, tell us about it, if you need support, ask us: Response.

The next releases will contain a Bean Factory and Application Context framework and of course - a documented Regular Expression (RegEx) framework. ;)
So, stay tuned!

October 13th, 2005

As2ant 1.0 beta, Released!

Changes include:

* Better readability of generated commandline output.
* Support for local variable inference: -infer
* Support for package-attribute: -pack
* New way of specifying sources, via XML

The new way of specifying sources via XML is especially important. Because this allows you to write a xml log configuration for the As2lib logging framework and specify this xml log configuration as source xml in your mtasc or swf tasks.

Check it out yourself!

Download As2ant 1.0 beta.

The next release will contain

* a task for As2api,
* fixes for all the bugs you encounter and
* implementations of new features you need.

I hope you enjoy working with the tasks!