Http://www.cnblogs.com/seacryfly/archive/2011/12/29/2305965.html
Only changes to the (unique) responsibility (requirement) of the class will cause the refactoring of the code.
The single responsibility principle states that every module or class should has responsibility over a single PA RT of the functionality provided by the software, and that responsibility should is entirely encapsulated by the class. All its services should is narrowly aligned with the that responsibility. Robert C. Martin expresses the principle as follows:[1]
“ |
A class should has only one reason to change. |
”
|
2.2 Single Duty principle
2.2.1 Introduction
A good system design, emphasizing the relationship between the module to maintain low coupling, high cohesion, in object-oriented design This rule also applies, so the object-oriented first design principle is: single responsibility principle (Srp,single Responsibility Principle).
A single duty, emphasizing the separation of duties, to a certain extent, the understanding of responsibilities, constitutes the key to the design of the coupling between different classes, so the single responsibility principle is more or less a basic principle that must be considered in the design process.
2.2.2 Classics
With regard to the principle of single responsibility, the core idea is:
A class, it is best to do only one thing, only a cause of its change.
The principle of single responsibility can be regarded as the extension of low-coupling, cohesion-poly in object-oriented principle, and defines responsibility as the cause of change, in order to improve cohesion to reduce the cause of change. The more responsibilities that may cause it to change, the more it will lead to a dependency on responsibility, which has an impact on each other, thus greatly damaging the cohesion and coupling degree. A single responsibility usually implies a single function, so do not implement too many functional points for the class to ensure that the entity has only one cause for it to change.
Therefore, the core of the SRP principle is that a change to a class can only be one, for a class that violates this principle should be refactored, such as façade or proxy mode separation of responsibilities, through the basic method Extract Interface, Extract The class and extract method are combed.
One of the five principles of object-oriented: Single responsibility principle (self-understanding)