High cohesion and low coupling

Introduction: Module Independence

 

meaning

 

Module independence means that each module only completes the independent sub-functions required by the system, and the connection with other modules is minimal and the interface is simple.

Module independence refers to a measure of the relationships between parts within a module and between modules, measured by cohesion and coupling .

 

The importance of module independence

 

Due to the division of functions, the interface is simplified, and software with independent modules is easy to develop, especially when multiple people develop projects in parallel.

In addition, independent modules are also easy to test and maintain. Modifications to designs and procedures require less effort, have less error radiation, and are easily scalable.

 

Cohesion & Coupling

Cohesion: How closely the elements within a module fit together.

Coupling: A measure of the degree of interconnection between different modules within a software structure.

 

The following is personal YY:

Whether it is high cohesion or low coupling, the essence is inseparable from the original intention of module independence, namely: independence (low coupling) and collaboration (high cohesion).

 

In the vernacular, it is similar to the fact that the various departments and departments within the school are independent of each other and work independently (low coupling). At the same time, each department will provide one or several offices (as few as possible, mainly for covering Chapter...) for external communication (interface).

 

But within the department, there are very close contacts between the various offices. And each office often only does a single thing (single function). I saw someone say on CSDN: The strongest cohesion is the single function that can no longer be split, that is, atomization. High cohesion means that the offices within the department should be closely linked, each performing its own duties, and achieving a common final function. If an office is loosely related to others (outliers?), consider a departmental adjustment.

 

Personally, in fact, there is a smaller granularity, such as coupling & cohesion between classes. The encapsulation of methods can be considered from cohesion and coupling, and then decide which class to encapsulate. The above is purely YY.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326646557&siteId=291194637