Friday, June 16, 2006

Just Another Blog: Dependency Injection OR Service Locator in Domain Objects
with Spring and Hibernate frameworks

This probably summarizes one of the nagging problems of making your domain objects rich.

Coming from a C/C++ background, one of the things that I missed when I started doing business applications in Java (or any business type application for that matter) is the richness of object oriented programming. Objects are lively, as in the case of a point object where you can "tell" it to move via point.move(x,y).

For business domain objects like an account for example, I would like it to be able to tell it to debit an amount via account.debit(amount). This doesn't come naturally for these types of applications since when they are revived from storage they only contain data.

For now, I do the "assembling" in the DAO objects and create new objects via an ImplementationLocator, which is basically a service locator that uses spring underneath. e.g. for the account DO, ImplLocator.getImpl("Account").

Hopefully in the future there would be a more natural way of doing this. Am still skeptical with AOP.

No comments: