Code Coupling

Coupling Code: a measure of degree of interconnection between different software modules within a structure (also called inter-block coupling contact means between the software architecture modules in close contact with each other a measure of the degree of close contact between the module. the stronger the coupling, the independence of the module is worse, the coupling between modules depends on the level of complexity of interfaces between modules, invoke, and information transmission.)

principles of software engineering provisions writing code is "high cohesion, low coupling. " Cohesion is the independence of the code block, is coupled between the respective contact block.

For low coupling, superficial understanding that: between a complete system, the module and the module, it is possible independent existence. In other words, so that each module, independently of a specific sub-functions as possible. The interface between the module and the module, the small and simple as possible.

Poly is a module within each element bonded to each other the tightness, high cohesion is high individual elements within a module how tightly bonded to each other inside the code. The so-called high cohesion refers to a software module is a strong correlation between the composition of the code, is only responsible for one task, which is often said that the single responsibility principle.

High cohesion, low coupling system, what good is it? In fact, short term, and there is no obvious advantage, even in the short term will affect the progress of the development of the system, because of the high cohesion, low coupling system development and design staff put forward higher requirements. Long term, low coupling module facilitates unit testing , and easy to maintain.

Example:
in java, you want to call a class in your program, for example, it is A1, if you direct new A1 in the program (), so you write died. Such as over the next business logic changes, you'll have to re-edit the code A1 class. In this case, if the A1 class is called by other programs, you modify the code for the class A1, might affect other programs.
But if you use to configure your class related attributes in the configuration file, obtained through dynamic regional program, you only modify the configuration file, he points to another class A2 on the line. Replace A1 with A2. This is the low coupling, is also facing increased java open, closed for modification principles.

Guess you like

Origin www.cnblogs.com/jfdwd/p/11258360.html