The single responsibility Principle of software Design (SRP) _ Design mode

Source: Internet
Author: User
Single Responsibility principle: there should be only one reason for a class to change (ASD).
I just learned to program, is to learn the C language introduction. C language is a process-oriented language, just beginning to get used to, to now write the program will also be oriented process thinking impact. When it comes to object-oriented programming (Java), it's natural to add a variety of functions to a class, and then write all kinds of code in a class. But the disadvantage of doing so is that if a class has too much responsibility, it is the equivalent of coupling those responsibilities together, and a change in responsibility may inhibit or alter the ability of other responsibilities. This coupling design can lead to fragile design, and when the change occurs, the design will suffer unexpected damage. If you write all the functions in the same class, the class is highly coupled, the code inside is inter-related, and if you want to change one of the codes, you'll probably be able to pull the whole body. Changing a place can affect many other places, causing a lot of trouble for later maintenance code and potentially causing a variety of bugs.
Much of what software design really does is to identify responsibilities and separate them from each other. Often when we write a program, if there are more than one motivation to change a class, then this class has more than one responsibility.
Related Article

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.