O'Reilly logo

Java 9 Programming Blueprints by Jason Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Services - exposing decoupled functionality

Before looking at the definition of our TopComponent, let's look at PhotoManager, and learn a bit about its services. The PhotoManager interface itself is pretty simple:

    public interface PhotoManager extends Lookup.Provider { 
      void scanSourceDirs(); 
      List<String> getYears(); 
      List<String> getMonths(int year); 
      List<String> getPhotos(int year, int month); 
    } 

There is little of interest in the preceding code beyond the extends Lookup.Provider portion. Adding this here, we can force implementations to implement the lone method on that interface, as we'll need that later. The interesting part comes from the implementation, which is as follows:

 @ServiceProvider(service = PhotoManager.class) public class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required