Chapter III Single Responsibility Principle

Define
(Single Responsibility Principle, SRP), also known as single responsibility principle Single Responsibility Principle, by Robert · C Martin (Robert C. Martin) in. "Agile Software Development: Principles, Patterns and Practice," a book made. Responsibility here is the reason for the change of class, single responsibility principles laid a class should have one and only one cause why it changes, otherwise the class should be split (There should never be more than one reason for a class to change).

The principles set forth object should not assume too much responsibility, if an object took on too much responsibility, there are at least two disadvantages:

  1. A change in responsibilities may weaken or inhibit the ability of this class implements other responsibilities;

  2. When a client needs a certain responsibility to the object had to be other unwanted responsibilities include it all, resulting in a waste of redundant code or code.
    Duty principle advantage of the single
    core particle size is controlled based principles single responsibility, decouple objects, to improve the cohesion. If you follow the single responsibility principle will have the following advantages:

  3. Reduce the complexity of the class. A class is only responsible for a duty, certainly better than its logic is responsible for a number of duties is much simpler. Improve the readability of the class. Reduce complexity, increase natural readability.

  4. Improve the maintainability of the system. Improve readability, it is much easier to maintain.

  5. Risk reduction due to change. Change is inevitable, if the single responsibility principle comply well, when modifying a function, you can significantly reduce the impact on other functions.
    Implementation principles single responsibility
    single responsibility principle is the principle of the simplest but most difficult to use, requiring designers to find different classes of functions and separating, and then encapsulated into different classes or modules. The class found various responsibilities require designers to have strong analytical capabilities and design experience related to reconstruction. Below job management program student at the University of example to introduce the application of the principle of single responsibility.

Guess you like

Origin www.cnblogs.com/liuxiany/p/12643826.html