Object-Oriented Design Principle-single Responsibility Principle

Source: Internet
Author: User
Definition
  • For a class, there should be only one reason for its change

    Inference 1 (basic)

    • A class should include the most basic and unchangeable core implementation, which is the core value of the class.
    • Core Value: different from the basic features of other classes, or the basic functions that classes should implement

      Inference 1 (Extension)

      • When changes reach the core implementation of a class, they must be replaced rather than modified.

      Inference 2

      • For a class, only the things that can be decided by the class should be left to the user for decision-making.

      Inference 3

      • For a class
      • Include the things that can be determined in the core implementation.
      • Choose the most common decision that cannot be determined by yourself as the default extension.
      • Remove things that cannot be decided at all.

        What I think when I look at a single responsibility principle. These theoretical books seem dull, but the more interesting they are.

        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.