• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Modular Java: flexibility

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do we achieve flexibility in the applications using OSGi and Spring?
 
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
great! thanks for the explanation... sounds interesting...
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic