High cohesion and low coupling appreciated

In doing rm the game in the process, we found that it is very important documents and specifications logic functions, which affects not only their own convenience or not look at the code, but also affect the next players to understand my code. Therefore intend to start their own code specification habits, develop good habits, work can also be used later on.

The following switched from Baidu Encyclopedia


 

Cohesion and coupling.

Coupling: is a measure of the degree of association between the modules. Strength depends on the complexity of the module is coupled between the interface, the calling module and the manner how much data is transmitted through the interface. The coupling means between modules dependencies between modules, comprising a control relationship, the relationship between calls, data transfer relationship. The more contact between modules, the stronger the coupling, also showed its independence worse. Reduce the coupling between modules can reduce the impact between modules, preventing wave effect "pull launched a whole" modifications to a module caused by system design to ensure the smooth progress. Coupling is associated, a perception and dependencies between modules (classes) with the other modules (classes) degree, is a measure of independence index code.

Cohesion: named Incredibles, represent between internal aggregation, the degree of relevance, so high is simply more highly cohesive aggregation and association. High cohesion is the relationship between class and class availability, high, meaning that the relationship between them should be simple, clear, do not have a strong relationship, otherwise, it will be a problem to run. Run a class affect other classes. Since polyethylene comprising a high reliability, reusability, readability advantages of modular design recommended high cohesion. A flag module cohesion within individual elements coupled to each other close degree, which is a natural extension of information concealment and localization concepts. Cohesion is measured from a functional point of contact within the module, a good cohesive module should just do one thing. It describes a functional relationship within the module.


 

Cohesion

Accidental cohesion:

  There is no link between processing elements within a module, but accidentally get together. This module is also called a coincidence cohesion, a minimum degree of cohesion.

Logical cohesion:

  Such a module to combine several related function is invoked each time, by the transfer module to determine which parameters to the function module to be completed.

Poly time:

  The module operation need to be performed in combination together to form a polymerization time module is called.

In the process poly:

  Or a combination of the operation member is allowed after the call operation member or the front, or immediately call back the operation member, even if no data is passed between them. Simply means that if the processing elements within a module are related, and must be within polypropylene, is known as performed in a specific order. For example, a function to complete the log, and a function of determining network state before, after a login operation is performed, is obviously performed in a particular order.

Communication within the 聚:

  It refers to all the processing elements within a module are in operation on the same data structure or all of the processing functions associated (sometimes referred to as the information poly) occurs through common data. It refers to the various components within the same module to produce the same data structures or data structure.

Cohesive sequence:

  A processing element of each module, and is closely related to a function, and these processes must be performed sequentially, after the input element of the one processing element output is typically a treatment before. To obtain a complete example of the order information function, a function of acquiring the former user information, calculation is performed after a median operation, apparently closely related two portions within the module. Cohesive order cohesion is relatively high, but the drawback is not as easy to maintain the functions of polyethylene.

Functional cohesiveness:

  The modules have all of the various components of the element are done in the same function exists together to accomplish a single function modules can not be divided. That module only includes all the ingredients necessary to complete a function, closely these ingredients, are indispensable.


 

coupling

Indirect coupling:

  There is no direct relationship between the two modules, the connections between them are entirely controlled by the main module and the calling to achieve. Coupling the weakest, most independent module.

Data coupling:

  Only simple transfer of data items between a calling module and a parameter module is invoked. Equivalent to the value passed high-level language.

Coupling tag:

  Call transfer between modules and the data structures are called modules rather than simply data, also referred to as coupling characteristics. Table is not a simple variable is passed between modules and, but as senior language data, record data such as name and file name result, these names shall be marked, in fact, delivered an address.

Coupling Control:

  Not data transfer between the modules, but the control information such as a flag, switch, etc., a function of the control module of another module.

External coupling:

  A set of modules are simple to access the same global variables, and do not pass through the information of the global variable parameter table, is called external coupling.

Public coupling:

  A module to access the same set of global data structure, is called common coupling. Public data can be global environment data structure, the communication area of ​​the shared memory of common coverage areas. If only the module data to the common data input environment, or retrieve data from only public data environment, which is a common loose coupling; if both extract data module and from the environment to the common data common data input environment data, which is a tighter common coupling.

Public coupling cause the following problems:

1. The various modules can not control access to common data, seriously affecting the reliability and adaptability of software modules.

2. Make the deterioration of maintainability of software. If a module to modify public data, it will affect the relevant module.

3. Reduce the intelligibility of the software. Not easy to clearly know what data is shared which modules, debugging difficult.

Generally, only very inconvenient when data shared between the many modules and parameter passing, before use of common coupling.

Content coupling:

  Direct access to a content module of another module, called the two coupling modules content.

When one of these occurs in the program, then the contents of the coupling between two modules:

1. a direct access to the internal data module to another module.

2. A module does not directly transferred to the inside of the other module via the normal inlet.

3. The module has two codes overlap portion (the portion of the code has some independent function).

4. The module has a plurality of inlets.

Content coupling can occur in assembly language. Most high-level languages ​​are designed to be coupled to the content is not allowed. This coupling is coupled strongest, weakest module independence.


Guess you like

Origin www.cnblogs.com/viggogao/p/11804466.html