O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

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

Using services to create loose coupling between consumer and provider modules

Generally, in our applications, we have some interfaces and multiple implementations of those interfaces. Then at runtime depending on some condition, we make use of some specific implementation. This principle is called Dependency Inversion. This principle is used by the dependency injection frameworks like Spring to create objects of concrete implementations and assign (or inject) into the references of type abstract interface. 

Java has for long (since Java 6) supported service-provider loading facility via the java.util.ServiceLoader class. Using Service Loader you can have a service provider interface (SPI) and multiple implementations of the SPI simply called ...

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