Here is how we can compare the Single Responsibility Principle with Coupling, Cohesion, and Separation of Concerns:
Single Responsibility Principle vs. Coupling
- SRP: Focuses on ensuring that a class has only one reason to change.
- Coupling: Focuses on minimizing dependencies between classes or modules.
- Relationship: Applying SRP can lead to lower coupling because when each class has a single responsibility, classes are less likely to depend heavily on each other.
Single Responsibility Principle vs. Cohesion
- SRP: Ensures that a class has a single responsibility.
- Cohesion: Ensures that the tasks performed by a class are closely related.
- Relationship: High cohesion often results from applying SRP because a class with a single responsibility will naturally have related tasks grouped together.
Single Responsibility Principle vs. Separation of Concerns
- SRP: Focuses on single responsibility within a class or module.
- SoC: Focuses on dividing the program into distinct features with minimal overlap.
- Relationship: Applying SRP is a way to achieve SoC. By ensuring that each class has a single responsibility, the overall design adheres to the principle of separating concerns.