Learnitweb

Aggregator module in Java

1. Introduction

Sometimes there is requirement to group related modules so that these can be read as a group. Else, each module needs to be read individually. That is why it is better to group related modules. We can group the related common modules in a single module, and we can read this module directly.

The module which aggregates several modules into a single module is called Aggregator module. If any module reads aggregator module then automatically all its modules are by default available to that module. If a module accesses the aggregator module, then all of its modules are inherently accessible to it by default.

The aggregator module itself does not offer any functionality; rather, it simply collects and consolidates a group of other modules.

2. Example of aggregator module

Following is an example of an aggregator module:

module aggregatorModule {
	requires transitive moduleA;
	requires transitive moduleB;
	requires transitive moduleC;
}

The Aggregator Module doesn’t need to include any Java classes itself. Instead, it only necessitates the requires transitive directive for all common modules.

If any module reads aggregatorModule automatically all 3 modules are by default available to that module also.

module myModule {
	requires aggregatorModule;
}

Now myModule can use functionality of all 3 modules moduleA, moduleB and moduleC.

3. Conclusion

Aggregator module itself does not provide any functionality but it is very important in designing and managing your modules efficiently.