Chapter 64. Package-by-Feature with the Default Access Modifier
Marco Beelen
A lot of business applications are written using a three-tier architecture: view, business, and data layers, and all model objects are used by all three layers.
In some codebases, the classes for these applications are organized by layer. In some applications, which have the need to register various users and the company they work for, the code structure would result in something like:
tld.domain.project.model.Company tld.domain.project.model.User tld.domain.project.controllers.CompanyController tld.domain.project.controllers.UserController tld.domain.project.storage.CompanyRepository tld.domain.project.storage.UserRepository tld.domain.project.service.CompanyService tld.domain.project.service.UserService
Using such a package-by-layer structure for your classes requires a lot of methods to be public. The UserService needs to be able to read and write Users into storage and, since the UserRepository is in another package, almost all methods of the UserRepository would need to be public.
The organization might have a policy to send an email to a user to notify them when their password has been changed. Such a policy might be implemented in the UserService. Since the methods in the UserRepository are public, there is no protection against another part of the application invoking a method in UserRepository ...