Chapter 5. Best practices for enterprise applications

 

This chapter covers

  • How to scope your OSGi bundles
  • The importance of keeping your bundle’s private bits private
  • Why static factory classes are no longer your friend
  • The whiteboard pattern, a better alternative to the listener pattern
  • Avoiding bad WAR habits, and why it makes sense to keep persistence code in its own bundle

In the first part of this book, we took a focused look at the Apache Aries project and how it can be used to write useful enterprise OSGi applications that leverage a combination of base OSGi modularity, enterprise services, and a lightweight programming model. Although this was an incredibly fast way to get to grips with enterprise OSGi, we feel it’s time now to take a step back and look at some of the principles underlying what we’ve been doing. Why did we structure the Fancy Foods application the way we did? What patterns should you be applying to your own applications?

5.1. The benefits of sharing—and how to achieve them in your bundles

You’re probably wondering why we make such a big deal about sharing code; sure it sounds great in theory, but is it ever practical? Even if it’s practical, is it worth the extra effort and loss of control?

5.2. Structuring for flexibility

5.3. A better enterprise application architecture

5.4. Summary