Spring_Program Coupling_hehe.employment.over.33.2

Article Directory

33.2 What is program coupling

  • Coupling , also called coupling degree, is a measure of the degree of association between modules. The strength of the coupling depends on the complexity of the interface between the modules, the way the modules are called, and the amount of data transmitted through the interface. The degree of coupling between modules refers to the dependencies between modules, including control relationships, call relationships
    , and data transfer relationships. The more connections between modules, the stronger the coupling, and at the same time, the poorer its independence (reducing the coupling can increase its independence). Coupling exists in various fields, not unique to software design, but we only discuss coupling in software engineering.
  • In software engineering, coupling refers toDependence between objects. The higher the coupling between objects, the higher the maintenance cost. Therefore, the design of objects should minimize the coupling between classes and components. In software design, coupling degree and cohesion degree are usually used as the standard to measure the degree of module independence. One criterion for dividing modules isHigh cohesion and low coupling
  • It is classified as follows:
    • (1) Content coupling. When a module directly modifies or manipulates the data of another module, or when a module transfers to another module without passing through the normal entry, such coupling is called content coupling. Content coupling is the highest degree of coupling and should be avoided.
    • (2) Common coupling. Two or more modules refer to a global data item. This coupling is called common coupling. In a structure with a large number of common couplings, it is very difficult to determine which module assigns a specific value to a global variable.
    • (3) External coupling. A group of modules all access the same global simple variable instead of the same global data structure, and the information of the global variable is not passed through the parameter table, which is called external coupling.
    • (4) Control coupling. A module transmits a control signal to another module through the interface, and the module that receives the signal performs appropriate actions according to the signal value. This coupling is called control coupling.
    • (5) Mark coupling. If a module A passes a common parameter to two modules B and C through the interface, then it is said that there is a tag coupling between modules B and C.
    • (6) Data coupling. Passing data between modules through parameters is called data coupling. Data coupling is the lowest form of coupling. This type of coupling generally exists in the system, because in order to complete some meaningful functions, it is often necessary to use the output data of some modules as the input data of other modules.
    • (7) Indirect coupling. There is no direct relationship between the two modules, and the connection between them is achieved entirely through the control and invocation of the main module.
  • to sum up:
    • Coupling is an important factor affecting software complexity and design quality. In design, we should adopt the following principles: If there must be coupling between modules, try to use data coupling as much as possible, use less control coupling, limit the scope of common coupling, and try to avoid using it. Content coupling.
  • Cohesion and coupling
    • Cohesion marks the closeness of the integration of various elements within a module, and it is a natural extension of the concept of information concealment and localization. Cohesion is to measure the connections within a module from a functional perspective. A good cohesion module should do exactly one thing. It describes the functional connection within the module. Coupling is a measure of the interconnection between the modules in the software structure. The strength of the coupling depends on the complexity of the interface between the modules, the point of entry or access to a module, and the data passing through the interface. The program emphasizes low coupling and high cohesion. That is, the various elements in the same module should be highly close, but the interdependence between the various modules is not so close.
    • Cohesion and coupling are closely related. A module with high coupling with other modules means low cohesion, and a module with high cohesion means low coupling with other modules. When designing software, we should strive to achieve high cohesion and low coupling.
  • Icon:
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq_44686266/article/details/114142276