|
In this article:
- What is coupling
- Degrees of coupling
- Types of coupling
What is Coupling?
Coupling is the degree to which a each of the modules in a program is dependent on other modules. Coupling may also be called dependency.
Coupling is oppsite to cohesion. A high degree of coupling translates into low cohesion while a low degree of coupling means high cohesion. Cohesion and coupling together are indicators of the quality of software and were invented by Larry Constantine who also developed Structure System Analysis and Design.
Degrees of Coupling
Coupling is found to exist in two degrees:
- Low coupling (which is also called loose or weak coupling)
- High coupling (which is also called tight or strong coupling)
Low coupling is when a particular module in a program is independent of other modules in the program. This signifies that it is not important for a module to understand how other modules have been implemented internally. It us enough for it interact with the other modules by using a stable interface. The advantage of such low coupling is that there is no change in any of the other modules when a particular module is changed or altered. When a computer system (or program etc.) possess low coupling, it is considered to be well structured and ideal.
High coupling, on the other hand, is a situation where modules of a program are not indpendent of one another and are closely related to each other. Though high coupling is mostly undesirable, it is necessary in some situations. This is often useful when high efficiency is desirable from a program or system. When a system is not highly coupled, there is a noticable increase in its performance. However, when it comes to software development, it proves extremely beneficial if high coupling is present in the system.
A low degree of coupling is desirable when making computer programs so that they are understood easily and are easy to maintain. Low coupling is paired with high cohesion.
High coupling is not without its cons. These are:
- A change in one module necessiates a change in others.
- Difficult to understand the program.
- Polymorphism, or, the ability to use the same set of definitions again and again without redefining them, is nearly impossible.
Often, low coupling maybe achieved by limiting the number of responsibilities a particular module has. For example, a module may be limited to do only the printing of output and not calculating the values to be printed along with it. This allows for modules to communicate less and less each other, hence making them lowly coupled.
Types of coupling
There are various types of coupling that may be identified from low degree to high degree. They have been discussed below:
- Data Coupling
When the modules in a program share data among themselves, it is known as Data coupling and it is most desirable form of coupling. This can be through various means. An example is the passing of parameters (or arguments) to a particular module by another module (which calculated them as a result of some operation).
- Stamp Coupling ( or Data-structured Coupling)
When instead of a single datum, a whole set of data (that is, a data structure) is shared by the modules in a program, it is a case of Stamp coupling. It is notable that the module sending the data structure to the other module will not know what part of that data structure will be used or processed by that module.
- Control Coupling
When a module in a program controls the working of another module in the same program, it is called as Control coupling. This maybe done by passing some information to the other module that alters the way it behaves.
- External Coupling
When the modules in a program are coupled as a result of an imposition by the program’s working, it is called external coupling. For example, they may be forced to communicate in a particular manner only.
- Common Coupling
When the same global data (or variable) is used by two or more modules, it is a case of Common coupling.
- Content Coupling
When a module depends on the internal working of some other module (as in the case of accessing a variable local to that module), the situation is called Content coupling.
|