Implementing sorting services

Now that we have an understanding of how to create and consume services, let's put this to practice in the address book viewer application. We'll create multiple sorting implementation modules and register these implementations as services. We'll then update the packt.addressbook module to use the ServiceLoader API to get the sorting instances, and then use one of these instances to sort the contacts list. Let's run through the five steps we've just learned in order to achieve this:

  1. Create the Java type that defines the service: We'll retain the interface SortUtil to be the common interface that various implementation types will use. The packt.sortutil module contains both the interface and implementation types ...

Get Modular Programming in Java 9 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.