1

As a consultant working for multiple companies that are using maven multi modules I have made the same discovery with all of them that I find strange. Lets say they want to build a webapp for a hospital that manages staff and patients. Assume that they are separate domains. The project would look like this:

hospital  
-hospital-controller  
--src/main/java  
---com.example.hospitalapp.controller.patients  
----PatientsController.java  
---com.example.hospitalapp.controller.staff  
----StaffController.java  
-hospital-service  
--src/main/java  
---com.example.hospitalapp.service.patients  
----PatientsService.java (public to be accessed by PatientsController)  
---com.example.hospitalapp.service.staff  
----StaffService.java (public to be accessed by StaffController)  
-hospital-model  
--src/main/java  
---com.example.hospitalapp.model.patients  
----Patient.java (public to be accessed by PatientsService)  
---com.example.hospitalapp.model.staff  
----Staff.java (public to be accessed by StaffService)  

Because of the module name in each package a class that is used in the module above has to be public. Which leads to the fact that for example the PatientsController can access PatientsService but also StaffService. If we omit that module name in the packages we could make them package-private. So we gain a package-by-feature structure and PatientsController can only access PatientsService.

In conclusion we have a top level package-by-layer multi module structure that helps us technically for building each module separate but also we have a package-by-feature structure over all modules.

Why would one not want to do that?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.