Time for action - creating the Book bean interface

Let's add the Book and MutableBook interfaces, which are the beans of our bookshelf. They are placed in the package com.packtpub.felix.bookshelf.inventory.api.

The Book interface only exposes read access to the book attributes. It is usually a good practice to separate immutable parts of the interface from mutable parts. This way, we can separate between parts of the application that do read-only access to the data and others that are allowed to update it. Javadocs have been removed for clarity.

public interface Book
{
String getIsbn();
String getTitle();
String getAuthor();
String getCategory();
int getRating();
}

We will extend this interface for the mutable type, which provides the additional write access to the Book bean:

public interface MutableBook extends Book
{
void setIsbn(String isbn);
void setTitle(String title);
void setAuthor(String author);
void setCategory(String category);
void setRating(String rating);
}

Tip

Did you notice that the interfaces we've just designed have no knowledge of OSGi? As we've seen in Chapter 1, Quick Intro to Felix and OSGi, OSGi requires very little to integrate with your application. Later in this chapter, we'll see Activators, which will be our first use of OSGi-specific API.

Have a go hero personalize the Book Bean API

There are many other potential candidates for the book attributes. The ones we've chosen previously are minimalistic.

Here are some you may want to add to personalize this implementation:

  • Start date: Date I started reading this book (optional)
  • Finish date: Date I finished reading this book (optional)
  • Front cover: An image of the book's front cover and so on
Have a go hero personalize the Book Bean API

You'll have to follow those additional attributes throughout the implementation, all the way to the graphics and text user interface.

Note

Don't forget to impact the version of the bundle according to the change!

Adding an optional attribute to the Book bean makes this attribute available to bundles that need it. However, it allows bundles that used the previous version to be able to use this one as well. It's a minor version change. If the added attribute is mandatory, then it's a major version change!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset