Python Rocks! and other rants 19.4.2004

2004-04-19

Continuous Design

I have written before about Growing a design. Key to the success of this technique is keeping your code clean using principles such as Don't Repeat Yourself and You Aren't Going to Need It.

In this article, Jim Shore chronicles his experience with this process. I particularly like the sidebar Design Goals in Continuous Design which summarizes much of what makes this technique work.

posted at 08:41:36    #    comment []    trackback []
 

Inversion of Control Frameworks

Whenever you hide an implementation class behind an interface, you have the problem of instantiating the concrete instances of the interface and giving them to the client code.

There are several ways to do this:

  • The client code can instatiate the instance directly
  • The instance can be stored in a global resource such as a singleton or registry
  • The code that instantiates the client can also create the instance and pass it to the client
  • An instance can be created from a global property using reflection

Each of these techniques has disadvantages:

  • If the client creates the instance then you can't substitute a different implementation without changing the client, and the benefit of using the interface is reduced.
  • Using a global registry, singleton or property makes the client depend on the global facility which makes testing and reuse more difficult.
  • Reflection is complicated when the instance had dependencies of its own, for example it needs configuration data or depends on other interfaces.

A solution to this problem that is gaining popularity is to use a framework with support for Inversion of Control (or, as Martin Fowler calls it, Dependency Injection). With this technique, client code can be written with no dependencies on global resources. The framework takes care of initializing the required instances and providing them on demand.

Martin Fowler has an article that explains the technique. Two frameworks that use this technique are Spring and PicoContainer.

posted at 08:28:48    #    comment []    trackback []
April 2004
MoTuWeThFrSaSu
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
2627282930  
Mar
2004
 May
2004

Comments about life, the universe and Python, from the imagination of Kent S Johnson.

XML-Image Letterimage

BlogRoll

© 2004, Kent Johnson