Why is OSGi Important?
Join the DZone community and get the full member experience.Join For Free
i’ve seen a number of blog posts and tweets lately asking some version of the question why is osgi important? if you’re one of the many people looking around at the increasing usage of osgi and wondering whether it matters to you, here’s my answer.
i’m going to start by making a pretty audacious claim, which is that osgi is one of the most important technologies to have arisen in the last 20 years . this does not mean, however, that osgi is a revolutionary technology. in fact, osgi is so important because it represents the logical next step in the long-term evolution of software development.
where we’re coming from
to understand what i mean, let’s go back 20 to 30 years to the time when object oriented languages first became popular. one of the main reasons we adopted oo at that time was because it allowed us to hide many of the implementation details of our code.
moving from procedural languages to oo languages allowed us to develop classes exposing a contract defined by a set of public methods.
the result was that much of our code was invisible outside of its class, and this had profound implications for the way we develop software. by accepting the apparent restriction of visibility we gained immense freedom . we gained the freedom to reuse classes without knowing their implementation details. we gained the freedom to refactor our code without worrying about the consumers of a class.
can you imagine what a pain it would be if you had to develop software without information hiding?
where we’re headed
now imagine what it would be like if you could hide not only the methods within a class but entire sets of classes within a jar. imagine that jars could define public contracts the same way classes do, and that these contracts would be enforced both during development and at runtime. imagine that we could achieve all of the benefits of information hiding (managing complexity, code reuse, testability, refactoring, etc.) at an entirely new level.
osgi makes this possible by offering up the standard java package as a new unit of information hiding. when our code is running inside of an osgi framework, each package in a jar can be either exposed or hidden from consumers of that jar.
just as a class has a small set of public methods representing its contract with consumers, a modularized jar (a bundle in osgi terms) has a small set of exported packages representing its public contract. the bulk of our code lives in internal packages hidden from other jars.
imagine being able to rename classes, split or combine classes, move classes from one package to another, move entire packages from one jar to another, all without having to worry about impacting the consumers of a jar. so many of these types of refactorings are skipped now out of fear. package level information hiding gives us the confidence we need perform these refactorings, allowing us to react with agility to the changing needs of our users.
modularity is inevitable
whether osgi in particular succeeds or not, jar level information hiding is inevitable. the benefits are simply too great to ignore, and in 5 or 10 years we’ll all be wondering how we could have possibly lived without it.
currently, osgi is the only tool we have to accomplish this. luckily for us it’s a well though-out, well tested, standards-based solution. i can’t think of one reason (besides perhaps its name) to develop an alternative to osgi. it’s here. it works. let’s use it.
it’s time for osgi
steve mcconnell has a great quote that really gets at the heart of what osgi is trying to achieve.
in code complete , he writes:
software development has advanced in large part by increasing the granularity of the aggregations that we have to work with.
because this granularity of aggregation is so critical, the move from unmodular to modular practices is as important as the move from procedural to object-oriented practices . for 20 years we’ve been limited to using the class as our unit of abstraction. as successful as that has been, it’s time to move on to modules. its time for osgi.
Opinions expressed by DZone contributors are their own.