[8] SRP: single Responsibility Principle

Source: Internet
Author: User
ArticleDirectory
    • Definition:

 

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.