Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Breaking Dependencies

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using POJO instead of framework-bound class is a pretty neat idea. I use a vendor framework that has a single EJB gateway and all POJOs behind that. Well, almost POJO. They got the first rule about not implementing EJB interfaces but broke the second rule about not having depencies on the EJB spec downstream. So we still suffer from recycling the whole server to test a one-line change.

How have you balanced removing dependencies on the container with taking advantages of its features, like security, transactions and such? I grok dependency injection ... do I wind up with a bunch of adapters from My Personal Set Of Interfaces to EJB implementations and mock implementations?
 
Chris Richardson
author
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are couple of ways to look at the issue of breaking dependencies on the container. One option is to use frameworks such as Spring, which provides transaction management, etc and Acegi Security, which provides security. These frameworks replace many of the services provided by the container - and in some cases are a lot more powerful.

The other option is to structure your code so that large portions of it are container independent and so can be tested outside of it. But, then use those services when deployed in the container. For example, your EJBs can delegate to POJOs, which are truely container independent.

Regarding dependency injection. One of the neat things about Spring dependency injection is that it can do things like inject an EJB local session bean interface into a POJO. It takes care of the JNDI lookup/home.create() boilerplate code. Your POJO gets a reference to the local interface without knowing where it came from. See http://static.springframework.org/spring/docs/1.2.x/reference/ejb.html#ejb-access. There is no need for adapters.

I hope this helps.

Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic