Return to site

JPMS: Service dependencies

=>AKA "provides...with" and "uses"

· java

uses

A uses module directive specifies a service used by this module—making the module a service consumer.
A service is an object of a class that implements the interface or extends the abstract class specified in the uses directive.

provides...with

A provides…with module directive specifies that a module provides a service implementation—making the module a service provider.
The provides part of the directive specifies an interface or abstract class listed in a module’s uses directive
and the with part of the directive specifies the name of the service provider class that implements the interface or extends the abstract class.

Java SE service loader wires desired implementation at Runtime.
It binds service providers to consumers.

Service consumer:

Service provider