1. Single Responsibility Principle
Created Thursday 14 August 2014
The SRP states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class.
Robert C. "Uncle Bob" Martin
There should never be more than one reason for a class to change.
How strongly-related and focused are the various responsibilities of a module
The degree to which each program module relies on each one of the other modules
Strive for low coupling and high cohesion!
Responsibilities are Axes of Change
- Requirements changes typically map to responsibilities
- More responsibilities == More likelihood of change
- Having multiple responsibilities within a class couples together these responsibilities
- The more classes a change affects, the more likely the change will introduce errors
- "a reason to change"
- A difference in usage scenarios from the client's perspective
- Multiple small interfaces (follow ISP) can help to achieve SRP
- Clean Code by Robert C. Martin [http://amzn.to/Clean-Code]