Analysis of Cohesion and Coupling Types and Comparison of Cohesion and Coupling Degrees of Software Design Principles


Preface

High cohesion and low coupling is an important principle that we must follow in the software design process, and it occupies a large proportion in the entire software engineering. As for cohesion and coupling, are you still limited to the fuzzy concept of "high cohesion, low coupling"? So how do you judge what is high and low? This article will take you to deeply analyze and summarize the 7 types and descriptions of cohesion and coupling, and help you to better judge the types in future project development and examinations!

Insert picture description here


1. What is cohesion?

Cohesion refers to the closeness of the connections between the various elements within the module, that is, the concentration of code functions.

1.1. 7 types of cohesion and their descriptions

The cohesion types of modules can usually be divided into 7 types. We sort them according to the degree of cohesion from high to low , as shown in the following table:

Cohesion type description
Functional cohesion To complete a single function, all parts work together, one is indispensable
Sequential cohesion Processing elements are related and must be executed sequentially
Communication within All processing elements are concentrated in a data structure area
Process cohesion Processing elements are related and must be executed in a specific order
Instantaneous cohesion The tasks included must be executed within the same time interval (eg: initialize the module)
Logical cohesion Complete a set of logically related tasks
Accidental cohesion Complete a set of unrelated or loosely related tasks

2. What is coupling?

Coupling refers to the closeness of interconnection between modules.

2.1. 7 coupling types and their descriptions

The coupling types of modules are usually divided into 7 types. We sort them according to the coupling degree from low to high , as shown in the following table:

Coupling type description
Indirect coupling No direct contact, independent of each other
Data coupling Pass simple data with the help of parameter tables
Tag coupling A part of a data structure is transferred by means of a module interface
Control coupling The information passed between modules contains information used to control the internal logic of the module
External coupling Related to the environment outside of the software
Common coupling Multiple modules refer to the same global data area
Content coupling One module accesses the internal data of another module.
One module does not pass the normal entry to the internal data of the other module.
Two modules have part of the program code overlap.
One module has multiple entries.

to sum up

This article introduces two core concepts in software design principles-cohesion and coupling, and expounds the two concepts. At the same time, the 7 types of cohesion and coupling are supplemented separately, so that we can judge their degree, and better design software systems with excellent performance during development, and try to reduce the subsequent maintenance and upgrades caused by poor cohesion and coupling. Troubled.

Insert picture description here


I am Bailu, a programmer who works tirelessly. Hope this article can be of benefit to you, welcome everyone's one-click three-connection! If you have any other questions, suggestions or supplements, you can leave a message at the bottom of the article, thank you for your support!
More information WeChat search public accountWDeerCode code circle

Guess you like

Origin blog.csdn.net/qq_22695001/article/details/109254666