ArticleDirectory
Agile Software development principles, models and practices (C # Edition)
Chapter 2 SRP: single Responsibility Principle
Definition:
"SRP: A class should have only one reason for change."(P89)
"In SRP, we define responsibilityReasons for change. If you can think of more than one motive to change a class, this class has more than one responsibility."(P90)
Partial summary
"If a class has too many responsibilities, these responsibilities are coupled. A change in responsibility may weaken or restrain this class from fulfilling other responsibilities. This coupling will lead to a fragile design. When a change occurs, the design will suffer unexpected damages."(P90)
Note: whether a class must adopt the SRP principle is clearly stated in the book.
"On the other hand, if the applicationProgramIs always caused by thisTwo ResponsibilitiesAt the same time, they do not have to be separated. In fact, separating them will lead to an unwanted smell of complexity."(P91)
"There is another inference here.The changed axis is of practical significance only when changes occur.If there is no indication, it is unwise to apply SRP or any other principles."(P91)
Note: The"Two Responsibilities", It doesn't mean that a class has only two responsibilities, because this sentence has context, because before this passage in the book, there is an example, this example lists the situations where a class has two responsibilities.
Conclusion
"SRP is one of the simplest and most difficult to use in all principles. We will naturally combine our responsibilities. A lot of work really needs to be done in software design is to discover responsibilities and separate those responsibilities from each other. In fact, the rest of the principles we will discuss will return to this issue in one way or another ." (P92)
Link:
[9] OCP: open-closed Principle