Introduction

Flash is a lightweight cross-platform runtime for rich media, enterprise applications and mobile applications, as well as an integrated development environment. Flash can be programmed in ActionScript 1/2/3.

Saturday, May 20th, 2006 at 1:27 pm

Inversion of Control Containers

An Inversion of Control container is an infrastructural backbone for applications by providing services like lifecycle management, lookup, configuration and dependency resolution.

Lifecycle management: The lifecycle of application objects is managed by the container. The container is able to create new objects, to populate them (applying property values), to invoke initialization and destruction callbacks.

Lookup: References to application objects can be obtained through the container. A container is so to speak a factory.

Configuration: Application objects can be configured in a consistent way (without needing recompilation); for example with an XML dialect.

Dependency resolution: The container should not only configure application objects with simple types, but also manage relationships between them.

While application objects should be able to take advantage of these services, they should NOT depend on the container. This can be achieved by Inversion of Control (and Dependency Injection). Inversion of Control containers are thus also called non-invasive containers.

IoC containers do not impose invasive dependencies on your code, but it is advisable to follow some good coding practices.

* Code to interfaces to maximize pluggability.
* Each application object should have a clear set of responsibilities.
* Favor the Strategy design pattern over inheritance.
* Do not write code to do anything that the container can do.
* Use method prefixes in a consistent manner (Mutator Methods: Naming)

If you follow the preceding recommendations, you can also easily unit test your code and practice test-driven development.

In the next article we are going to take a look at the As2lib IoC container for Flash and its simple XML dialect.