Friday, May 05, 2006

The Idiot and dependency injection


Detail from The Body of the Dead Christ in the Tomb, Hans Holbein, 1520. This painting plays a central part in Dostoevsky's novel The Idiot which our book club has just read. At the same time, reading about Dependency Injection in the Spring Framework caused conceptual conflation between Christianity and object-oriented programming, as follows.

Prince Myshkin the "idiot" is supposedly a Christ figure, though that was not obvious to me. His innocence waxed and waned depending on the requirements of the plot. But it got me to thinking about the elegance of the structure of Christian belief. Namely that Christ has suffered and died on the cross, to atone for sins you have yet to commit. He has pre-suffered for your convenience. Since as a fallible human you have sinned and (this is the key) will continue to sin, Christianity offers the attractive benefit of a pre-solution. Your problems have already been solved, by Christ's suffering, even before you have them. To take advantage of this great offer, you must merely sign up, to believe His word, and obey Him. In return for which you will get 90 virgins (oops wrong religion), salvation and eternal life in heaven with Him. But hurry, time is limited!

Similarly the Spring framework offers a pre-solution to the problems your Java bean classes will encounter, even before they have them! The Spring framework injects necessary functionality into your bean classes. To take advantage of this great offer, your bean classes must merely sign up, in the spring-servlet.xml file, and obey Spring.

In both cases shortcomings yet-to-happen have been extracted from the unit (a bean class, or you), pre-solved, then made available back to the unit. The result is an improvement in efficiency, at an affordable price!

A pattern that resurfaces in such different domains is compelling indeed.

No comments: