Providing Loose Coupling Between Modules - Java Object Oriented Design

Java examples for Object Oriented Design:Module

Introduction

A service consumer can specify loose coupling by specifying a "uses" clause in the module descriptor to indicate that the module makes use of a particular service.

The following example could be used for a module that may have the task of providing a web service discovery API.

module org.mymodule.serviceDiscovery { 
    requires public.java.logging; 
    exports org.mymodule.serviceDiscovery; 
    uses org.mymodule.spi.ServiceRegistry; 
} 

A service provider must specify that it is providing an implementation of a particular service by including a "provide" clause within the module descriptor.

In this example, the following module descriptor indicates that the service provider module provides the org.mymodule.spi.ServiceRegistry with the implementation of org.dataregistry.DatabaseRegistry.

module org.dataregistry { 
    requires org.mymodule.serviceDiscovery; 
    provides org.mymodule.spi.ServiceRegistry 
        with org.dataregistry.DatbaseRegistry; 
}

Related Tutorials