This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Modular Java: flexibility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Modular Java: flexibility" Watch "Modular Java: flexibility" New topic
Author

Modular Java: flexibility

Aarti Malhotra
Greenhorn

Joined: Dec 20, 2006
Posts: 14
How do we achieve flexibility in the applications using OSGi and Spring?


Aarti Malhotra
SCJP 5.0, SCWCD 5.0
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Aarti Malhotra wrote:How do we achieve flexibility in the applications using OSGi and Spring?


Flexibility is attained by having loosely-coupled elements in your application. This is true with DI and more so with OSGi.

Think about plain-old dependency injection for a moment. When your objects are given the objects that they use and only know about those objects through a common, stable interface, then you can swap out implementations of those objects transparently. That is, if FooImpl is given an implementation of Bar and only knows about Bar through the Bar interface, you should be able to give FooImpl *any* implementation of Bar without changing FooImpl. That, by itself, offers a lot of flexibility.

OSGi takes it a bit further. Rather than saying "Here's a BarImpl...wire it into that property of type Bar.", OSGi says "Hey...anyone got a Bar?" FooImpl would be wired with a Bar, but not even the Spring configuration knows what the implementation will be. It only knows that it will be given a Bar...how that Bar is implemented is a separate concern handled by the OSGi framework. The OSGi framework, when asked for a Bar, will search its service registry for services that implement Bar.

The nice thing about this is that Bar implementations can come and go, have multiple versions, and all sorts of other dynamic things at runtime. But OSGi handles it all gracefully. (The details of how it handles the dynamic nature of services is *way* to detailed to outline here...suffice it to say that you usually don't need to worry too much about it...it just works. In some cases, you may have to help it out a little, but for the most part, it just works.)

Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Aarti Malhotra
Greenhorn

Joined: Dec 20, 2006
Posts: 14
great! thanks for the explanation... sounds interesting...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Modular Java: flexibility
 
Similar Threads
MEN's Brain VS WOMEN's Brain
page flow best practice
Is this an Overhead with Struts!!!
OO Concepts
interfaces