For example,
if an abc.print module implements an org.printing.Print service interface defined in PrintServiceAPI module using com.abc.PrintImpl class,
then this is how its module-info should look:
module abc.print{
requires PrintServiceAPI; //required because this module defines the service interface org.printing.Print
provides org.printing.Print with com.abc.PrintImpl;
}
Yes, it is a best practice but not a requirement. In this case, the problem statement says that the module is PrintServiceAPI, so that is why the module abc.Print's module-info has "requires PrintServiceAPI;" clause.
If you like our products and services, please help us by posting your review here.
module abc.print{
requires PrintServiceAPI; //required
//because this module defines the service interface org.printing.Print
provides org.printing.Print with com.abc.PrintImpl;
}
Is this correct that, nobody can uses com.abc.PrintImpl, due to lack of the exports word?
Nobody refers to PrintImpl class directly. Other modules who want to use the Print service use the Print interface only (which is in PrintServiceAPI module). So exporting the package containing PrintImpl from abc.print module is not required. In fact, it is not even recommended to export com.abc.PrintImpl from ab.print module because you don't want anyone to accidently start using PrintImpl directly.
If you like our products and services, please help us by posting your review here.