What is the coupling? - Spring (II)

What is the coupling procedure?

  Coupling, also known as coupling, is a measure of the degree of association between the modules. Coupling strength depends on the complexity of the interface between the modules, and the calling module way how much data is transferred through the interface.

  The coupling means between modules dependencies between modules, comprising a control relationship, the relationship between calls, data transfer relationship.

  The more the relationship between module coupled is stronger, while showed its independence worse. Reduce the coupling, its independence can be improved.

  Coupling exists in all areas, rather than software designs unique.

  In software engineering, coupling refers to dependencies between objects. The higher the coupling between objects, higher maintenance costs. Therefore, the design should be allowed to object coupling between classes and components as small as possible.

  Software design and the degree of coupling is generally used as a measure of the cohesion degree of independence of the standard module. A division criteria module is coupled to highly cohesive.

  Coupling is an important factor in software complexity and design quality, the design of the above, we should adopt the following principles: If it is necessary there is a coupling between modules, to try to use data coupling, less use of controlled coupling, to limit the scope of common coupling, try to avoid the use of content coupling.

 

The type of coupling

  When the content of the coupling, when a module or directly modify the operating data of another module, or a module without other modules and proceeds through the normal entry, such a coupling is coupled referred to as content. Content coupling is coupled to the highest degree, try to avoid using.

  Common coupling, two or more modules together reference a global data item, this coupling is called common coupling. In the structure having a large number of common coupling, the global variable to determine which module is attached to a specified particular value it is very difficult.

  External coupling, a set of modules are simple to access the same global variable instead of the same global data structures, and not transmitting the information through the global variable parameter table, is called external coupling.

  Coupling control, a module transmitting a control signal via the interface module receives a signal to perform appropriate action based on the signal value, this coupling is referred to as a control module coupled to another.

  Tag coupling, if a module A via the interface passing parameters to a common two modules B and C, the presence of a marker coupled between said B and C.

  Data coupling, to communicate data between the modules parameter, then referred to as data coupling. Is a minimum data coupling acting coupling, coupling systems of this type are usually present, because in order to complete some meaningful function, often require some modules output data as input data to other modules.

  Indirect coupling, there is no direct relationship between the two modules, the connections between them and the control of calls entirely through main module implemented.

 

Cohesion and coupling

  Cohesion represents each element within a module to one another how tightly bound, it is a natural extension of information concealment and localization concepts.

  Cohesion is from a functional perspective to measure the relationship between the modules, a good cohesive module should just do one thing.

  It describes cohesive functional relationship within the module, is coupled to each heterogeneous metric between software modules interconnected structure.

  Coupling strength depends on the complexity of the interface between the modules, entering the access point or a module and the data interface.

  Coupling procedure is a low stress, high cohesion. Is the same among the various elements of a module height of close to, but the interdependence between the various modules have to be less tight.

  Coupling and cohesion are closely related, the presence of high coupling modules with other modules mean low cohesion, and high cohesion between modules means that the module with other modules is coupled to low.

  Making software design, we should strive to achieve high cohesion, low coupling.

 

Coupled ideas to solve

  Jdbc is driven by reflection to register, the benefits at this time is that we no longer depend on the specific class of driver class, this time even if deleted Mysql driver jar package, you can still compile. Hardcoded fully qualified name of the class, also can be solved by using a configuration file configuration.

 

Factory mode decoupling

  In practice in development, we can put three objects are configured using the configuration file, when you start the server application is loaded, so that the method in a class by reading the configuration file, to create these objects out and save it. When took in directly take over with it.

  This reads the configuration file and create an object of class is acquiring three factories.

 

Inversion of Control -Inversion Of Control

  The rights object to create a frame, the frame is an important feature, not object-oriented programming terminology. It includes dependency injection and dependent lookup.

  Ioc is the reduction of the role of coupling a computer program.

  First consider a problem, created out of objects stored? Multiple objects definitely need a collection stored. In the end is selected Map or List, you need to look to see if there is no demand, there needs to choose Find Map.

  When the application is loaded, create a Map, used to store three objects, it is called the Map container.

  Our plant is responsible for acquiring the specified object from the container class, when we get the original object is to use new way to take the initiative to get. Now when we get the object, and at the same time to plant, a factory or create objects for us to find, passive acquisition.

  This passive way of receiving and obtaining the object of thought is inversion of control, it is one of the core Spring Framework.

 

Guess you like

Origin www.cnblogs.com/guancangtingbai/p/12617134.html