1. What is cohesion? What is coupling?
Cohesion is to measure the relationship between modules from a functional perspective. A good cohesion module should do exactly one thing. It describes the functional connections in the module;
Coupling is a measurement of the interconnection between modules in the software structure from the module perspective, the coupling strength depends on the complexity of the inter-Module Interface, the entry or access point of a module, and the data through the interface.
Coupling, also known as inter-block connections, refers to a measurement of the degree of mutual closeness between modules in the software system structure.
The closer the relationship between modules, the stronger the coupling, and the poorer the module independence. The coupling between modules depends on the complexity of Inter-module interfaces, the call methods, and the information transmitted.
For example, an item is a module, a user item is a module, and a user money is a module. Therefore, there should be no connection between the three modules, functions in the module should be closely related.
For example, in the user item module, this module adds the item reduction function to the user. These two functions should be closely related because they use the variables or data shared between them.
2. What types of cohesion are there? What are the coupling categories?
Cohesion can be divided into the following types:
(1) Accidental cohesion: the code in the module cannot define calls to different functions. However, it enables the module to execute different functions, which are called coincidence intensity modules.
(2) logical cohesion: This module combines several related functions. Each time it is called, it is sent to the module parameters to determine which function the module should complete.
(3) Time cohesion: Combine the actions to be executed at the same time to form a time cohesion module.
(4) process cohesion: A combination of components or operations allows immediate call of components or operations after the previous component or operation is called, even if no data is transmitted between the two.
(5) communication cohesion: All processing elements in the module operate on the same data structure (sometimes called Information cohesion ), or, each processing process uses the same input data or generates the same output data.
(6) sequential cohesion: each processing element in a module is closely related to the same function and must be executed sequentially. The output of the former function element is the input of the next function element.
(7) function cohesion: This is the most powerful cohesion. It means that all elements in the module can complete a function together, which is indispensable.
Coupling can be divided into the following types:
(1) content coupling: in the following circumstances, content coupling occurs between two modules.
One module directly accesses the internal data of another module
One module fails to be transferred to another module through the normal portal;
Some program codes of the two modules overlap (may only appear in the assembly language );
A module has multiple portals.
(2) Public coupling: if a group of modules access the same public data environment, the coupling between them is called public coupling. A public data environment can be a global data structure, a shared communication area, and a public coverage area of the memory.
(3) External coupling: A group of modules access the same global simple variable instead of the same global data structure, and are called external coupling if the information of this global variable is not transmitted through the parameter table.
(4) control coupling: If a module clearly controls the function of selecting another module by transmitting control information such as switch, sign, and name, it controls coupling.
(5) Tag coupling: A group of modules transmit the record information through the parameter table, that is, tag coupling. This record is a sub-structure of a data structure, rather than a simple variable. In fact, the address of the data structure is passed, that is, the address transfer.
(6) Data coupling: it refers to the call relationship between two modules, which transmits simple data values. When one module accesses another module, they exchange input and output information through simple data parameters (not control parameters, public data structures, or external variables), which is equivalent to passing values in advanced languages.
(7) non-direct coupling: there is no direct relationship between two modules. The connection between them is completely achieved through the control and call of the main module.
Coupling strength depends on the following factors:
(1) calls from one module to another;
(2) Data Volume transmitted by one module to another module;
(3) The amount of control a module has applied to another module;
(4) Complexity of interfaces between modules.
Source: http://blog.sina.com.cn/s/blog_61b570ab0100ggil.html