The principles of the five major design principles (ii)---single duty principle

Source: Internet
Author: User

The single responsibility principle (Srp:single responsibility principle), also known as the single function principle, stipulates that a class should have only one reason for change.

If a class takes on too much responsibility, it is tantamount to coupling those responsibilities together. A change in one's responsibilities may weaken or inhibit the ability of this class to perform other duties. This coupling leads to a fragile design that, when changed, is subjected to unexpected damage. If you want to avoid this phenomenon, we should observe the principle of single responsibility as much as possible. The core of this principle is decoupling and enhancement of cohesion.

Benefits of a single responsibility:

1. The complexity of the class, the realization of what responsibilities are clearly defined

2. Readability improves, complexity, and of course readability improves

3. Improved usability and readability, which is of course easy to maintain.

4. The risk of change caused by the reduction, change is essential, if the interface of a single responsibility to do a good job, an interface modification only to the corresponding implementation of the class has an impact on the other interfaces have no impact, which is very important for extensibility, maintainability is very helpful.

The principles of the five major design principles (ii)---single duty 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.