Let's begin our journey of understanding services with a concept that you should be very familiar with as a Java developer--polymorphism. It starts with one interface and (possibly multiple) implementations of that interface. Although interfaces are not strictly necessary for services, they are still a good place to start. Let's say you define a service interface called MyServiceInterface
that looks like this:
package service.api; public interface MyServiceInterface { public void runService(); }
Now you can have multiple modules containing classes that implement this interface. Since all those modules need access to this interface, let's throw this interface into a module of its own, called service.api
, and expose the package that the interface MyServiceInterface
is in. Then each implementation module can require the service.api
module and implement MyServiceInterface
.
Consider there are three implementations of MyServiceInterface
in three corresponding...