Java Reference
In-Depth Information
Figure 1.4 A well-structured application with objects grouped inside modules. Dependencies between
modules are clearly identified. This is typical of the application structure that can be achieved with OSGi.
By enforcing a higher level granular structure on Java application code, OSG i bun-
dles strongly encourage good software engineering practice. Rather than spaghetti
code being easy to produce accidentally, it's only possible to load and use other
classes that are explicitly intended for you to use. The only way to write spaghetti in
OSG i is to deliberately expose the guts of your OSG i bundle to the world, and even
then the other bundles still have to choose to use your packages. In addition to mak-
ing it harder to write spaghetti, OSG i also makes it easier to spot spaghetti. A bundle
that exports a hundred packages and imports a thousand is obviously not cohesive
or modular!
In addition to defining the API that they expose, OSG i bundles also completely
define the packages that are needed for them to be used. By enforcing this con-
straint, OSG i makes it abundantly clear what dependencies are needed for a given
bundle to run, and also transparent as to which bundles can supply those dependen-
cies. Importing and exporting packages goes a long way to solving the issues
described in this section, because you no longer have to guess which JAR file is miss-
ing from your classpath. In order to completely eradicate classpath hell, OSG i has
another trick up its sleeve—versioning.
VERSIONING IN OSGI
Versioning is a necessary complement to modularity. It doesn't sound as enticing as
modularity—if we're being perfectly honest, it sounds dull—but it's essential if modu-
larity is to work at all in anything but the simplest scenarios. Why?
Let's imagine you've achieved perfect modularity in your software project. All your
components are broken out into modules, which are being developed by different
teams, perhaps even different organizations. They're being widely reused in different
Search WWH ::




Custom Search