Pay attention to software quality-read the feeling of design on the surface

Source: Internet
Author: User

Question: I am reading the book "design: The Evolution nature of Professional Software Development" (won the 19th jolt Productivity Award). I wrote my thoughts and comments, just as I thought.

 

Encapsulation, cohesion, and coupling are the primary principles of coding.

These three principles are not only available for object-oriented development. As early as the process-oriented development method, they have already existed as a universal principle. If you ask a software engineer casually, you can refer to "High Cohesion, low coupling. In the object-oriented method, the concept of "encapsulation" is further enhanced, and attributes and behaviors are encapsulated by class design.

In the actual coding process, let alone the meaning of the three words, which is not necessarily true.

For encapsulation, we can see that public \ protected \ private is not used, and all of them are public. If you ask why, the answer is "maybe others can use this method", Khan!

Let's look at cohesion. For class cohesion, the most common problem here is to define a class by putting the relevant methods together. This requires us to talk about the advantages of object-oriented methods. Originally, we used class definitions to resolve the ing between the problem domain and the solution domain. Now we are away from the problem domain to define the class, we say this cohesion is inappropriate. For method cohesion, when we find that the name of a method is inconsistent with the content of the method, or a method cannot find a proper name, it is often against the cohesion principle.

For coupling, it should be noted that it is low coupling rather than zero coupling. If there is no coupling, the software will be released. There are two types of coupling. One is intentional coupling, which is the inevitable coupling determined in the design scheme, and the other is accidental coupling. Instead of being designed, the coupling is quietly integrated into the system. However, you must also identify whether intentional coupling is really required. The design verification we perform during the design phase is often judged on this point.

The above are the basic principles for improving software quality. There are also several software quality standards, namely redundancy, readability, and testability.


Redundancy is repeated.CodeSegment, the more common is the so-called clipboard inherited, copy a piece of code, do not change or slightly modified to enter the product library, such code generated redundancy eventually leads to reduced maintainability, modify one place and forget the other. In some cases, inheritance coupling can be introduced to reduce redundancy and put public code into the base class. However, pay attention to whether the context meaning is allowed.

Readability emphasizes code style consistency, naming accuracy, and so on. Remember, it is difficult to write code into any machine that can be understood.

We have not considered much about testability, but whether or not we have implemented a unit test, if we can consider testability when designing code, in fact, it is also the principle of encapsulation, cohesion, and coupling. If we can really put unit tests together in the engineering process, the improvement of software quality will undoubtedly get twice the result with half the effort.


-- Welcome to reprint, please indicate the source of http://blog.csdn.net/caowenbin --

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.