File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Modular Java: flexibility

 
Aarti Malhotra
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we achieve flexibility in the applications using OSGi and Spring?
 
Craig Walls
author
Ranch Hand
Posts: 363
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Aarti Malhotra
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great! thanks for the explanation... sounds interesting...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic