Big talk design model Reading Notes 2-single responsibility principle (SRP)

Source: Internet
Author: User

Single Responsibility Principle (SRP): For a class, there should be only one reason for its change. If a class has too many responsibilities, it is equivalent to coupling these responsibilities. A change in responsibilities may weaken or suppress the class's ability to fulfill other responsibilities. When a change occurs, the design will be unexpectedly damaged. Much of software design really needs to do is to discover accusations and separate those responsibilities. If you modify a class for more than one reason, this class has more than one responsibility.

Code Source: Agile Software Development (C)

1 public interface Modem
2 {
3 public void Dial (string pno );
4 public void Hangup ();
5 public void Send (char c );
6 public char Recv ();
7}

The interface shows two responsibilities:

1. Connection Management: the Dial and Hangup functions are used to manage modem connections.

2. Send and Recv data communication.

 

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.