Difference Between Coupling vs Cohesion
Software Engineering, as a discipline, is primarily a conglomeration of individualistic processes, aggregated to form a single outlook, more like a Coupling. A coupling, in layman terms, is a measurement of the degree of interdependence that occurs in between modules of the software. It more or less measures the strength of the inter-module relationship and how well connected they are.
A good programming practice is borne out of the need to maintain code cleanliness and remove clutter. Larry Constantine, in 1961, had suggested in the seminal work, Stevens, Myers & Constantine (1974), the importance of a structured design, which may lead to high readability and effective maintenance. Some studies show that clean code writing also leads to a certain reduction of costs arising out of maintenance.
What is Coupling?
A coupling is, as stated previously, is the measurement of the interdependence between modules. There are quite a few dependencies, that coupling is based on:
- The complexity of the interface existing between modules
- At which point is it referred to in a module
- The amount of data that is allowed to pass through the interface
Any module possessing a high degree of coupling and low cohesion is ideally said to be independent functionally in respect to other modules. Interface complexity decides on the severity of coupling between modules.
There are different types of Coupling when it comes to procedural programming:
- Data Coupling: Any two module interacting through a set parameter
- Stamp Coupling: Any two module interacting through composite data
- Control Coupling: If one set of data in module A is used to direct instructions in module B
- Common Coupling: Any two module interacting through global items
- Content Coupling: Module A using the code of Module B
Object-oriented programming or OOP has its own set of coupling types too.
- Subclass Coupling: Description of Child and Parent
- Temporal Coupling: Bundling of two actions in a single module based on similar timing
Other sets of Coupling are:
- Dynamic Coupling: Provides the run time evaluation of a system
- Logical Coupling: This digs deep to research the release history of the system and studies patterns.
- Semantic Coupling: Is based on the similarities of software systems, conceptually.
Each type of coupling comes with its own set of features, with benefits as well as disadvantages.
One thing that needs need to be remembered, in context to coupling is that though interface complexity plays an important role in measuring the degree of coupling between modules, it is also the amount of data that is interchanged between them that decides how interdependent they are.
What is Cohesion?
While coupling dealt with the interdependence of modules, cohesion deals with the module itself. It is a measurement of the functional strength of a module in relation to others. An ideal module would be one with high cohesion and low coupling. What that would mean, is that under those circumstances, the module would be independent functionally compared to other modules. Another scenario of an ideal module would be the one where it performs a single task.
Cohesion can be of different types:
- Coincidental Cohesion: If it performs tasks, loosely based on each other
- Logical Cohesion: All elements performing similar operations
- Temporal Cohesion: All functions to be executed together
- Procedural Cohesion: If it’s a single algorithm or procedure driving the cohesion
- Communicational Cohesion: If the same data structure is updated
- Sequential Cohesion: If the module consists of elements that are part of the sequence.
- Functional Cohesion: If disparate elements come together to form a singular function
Head to Head Comparisons Between Coupling vs Cohesion (Infographics)
Below are the top comparisons between Coupling and Cohesion:
Key Differences Between Coupling vs Cohesion
Let us discuss some of the major key differences between Coupling and Cohesion:
The terms coupling and cohesion are an integral part of programming terminology. They are frequently used terms, mainly used to describe the independence or interdependence of modules and their relative strengths.
- Coupling is defined as the degree of interdependence of modules while Cohesion is defined as the degree of strength of individual modules in relation to others.
- Low Coupling would mean that greater independence of individual modules while low cohesion would mean a weaker set of functional interdependence within a said module.
- Cohesion relies on the knowledge of the internal mechanism of a module while Coupling is based on the entry mechanisms of different modules
- Intra dependency of functions within a module is the bedrock of Cohesion while interdependency of modules is the fundamental pillar of Coupling
- As the names suggest: Cohesion is keeping together while Coupling is joining together
Comparison Table of Lightroom CC vs Lightroom Classic
Let’s look at the top comparisons between Lightroom CC and Lightroom Classic.
|Coupling is intra modular, that is indicating the relationship between different modules||Cohesion is intra modular, indicating the strength of the relationship, within the said module|
|Is a measure of the degree of independence, each module can enjoy||Is a measure of the individual modular strength in relation to the other modules|
|Gives us a glimpse of the degree of interdependence of a module can have with other modules||Is the degree to which a module can focus on a single function|
|Low coupling is always advisable since that would decrease the interdependence of modules||High cohesion is always advisable because that would increase the degree of focus on a single task or function, rather than increasing more interaction between other modules|
|Loose coupling is inherent to Private Fields, methods which are private and classes which are made nonpublic||Data Hiding is one of the prime examples of Cohesion|
|As stated before, the coupling is sole inter-module||Cohesion is intra module|
Both Coupling and Cohesion are important cogs in the wheel. Modules in software programming have to be both interdependent and intra dependent. If the functions are not properly executed, both at the inter and intra level, then the probability of the entire software system failing is high. Hence, it becomes imperative to define both the cohesion and coupling well. Another thing that needs to be mentioned here that both cohesion and coupling are dichotomous to each other. For example, Low Coupling and High Cohesion leads to more module independence. Similar the reverse may often lead to a software failure.
This is a guide to Coupling vs Cohesion. Here we discuss the difference between Coupling vs Cohesion with comparison table, key differences and infographics. You can also go through our other related articles to learn more –