How does SRP apply at the module/package level?
Answer
SRP scales beyond classes to modules, packages, and services. At the package level, SRP manifests as the Common Closure Principle (CCP): classes that change for the same reason should be in the same package; classes that change for different reasons should be in different packages. A package that mixes domain logic, infrastructure code, and presentation logic has multiple reasons to change — violating package-level SRP. In practice, this means organizing packages by feature/domain (vertical slicing) rather than by technical layer (horizontal slicing). A users package contains the user model, repository, service, and controller — all things that change when the user feature changes. This reduces the need to modify multiple packages for a single feature change.
Previous
How do SOLID principles relate to YAGNI and DRY?
Next
What are common misconceptions about OCP?
More SOLID Principles Questions
View all →- Intermediate How would you refactor a class that violates SRP?
- Intermediate How does the Strategy pattern support OCP?
- Intermediate What are the conditions for LSP compliance?
- Intermediate How does ISP prevent "fat interfaces"?
- Intermediate What is the difference between DIP and dependency injection containers?