we’re currently developing a rich application using Eclipse on client side and Spring Framework on serverside.
My challenge is to reduce implementation efforts by sharing the same business functions (services) over different applications. These business functions (e.g. a checkin/checkout service in document management context) can have different characteristics (e.g. checkin itself is equal, but in one application the file gets deleted after checkin, the other application will do nothing).
In this case I could copy & paste all code an adapt it to the new requirements, or i will find another nice solution (e.g. code reusing with callbacks, etc.) to reduce loc and maintenance efforts.
Do you have any experience in such scenarios? Does Spring provide any solutions for such a multiple application approach on one platform?
Of course, in fact Spring (IoC in general) is made for such solutions. First the technical step: extract the services that are suppose to be shared into a library that you can drop to different projects.
Now the fun part: if some pieces of logic are different while others remain the same, use dependency injection and strategy pattern!
And now create two independent implementations of
CheckInCleanupinterface, distinct to every application. One deleting the file and one doing nothing. In one application the former will be injected and the latter in the second one.CheckInCleanupis part of the library includingCheckInService, but the implementation is local. Spring will pick it up on startup and inject it automatically.Besides you have just introduced nice separation of concerns and increased testability.