Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
1.1.
What is Coupling?
1.2.
Types of Coupling 
1.3.
What is Cohesion?
1.4.
Types of Cohesion
2.
Difference Between Coupling and Cohesion
3.
Advantages of low coupling
4.
Advantages of high cohesion
5.
Disadvantages of high coupling
6.
Disadvantages of low cohesion
7.
Frequently Asked Questions
7.1.
What is coupling and cohesion in software engineering?
7.2.
What are the 4 types of cohesion?
7.3.
What is called coupling?
7.4.
What is coupling in oops?
7.5.
What is the basic difference between Coupling and cohesion?
8.
Conclusion
Last Updated: Apr 20, 2024
Easy

Cohesion and Coupling in Software Engineering

Author Gaurav Joshi
1 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Coupling and cohesion are fundamental concepts in software engineering, assessing the effectiveness of a software system's design. Cohesion and coupling is very essential to build maintainable, scalable, and resilient software applications.

Cohesion and Coupling in Software Engineering

In this article we are going to discuss the two essential terminologies of software designing, i.e. Coupling and cohesion, their type, differences, and characteristics of good software

What is Coupling?

Coupling is the degree to which two modules are interrelated. It measures the degree of interdependence between the modules. Coupling indicates the strength of dependencies between the modules. E.g. In a loosely coupled system, modules are less dependent on each other and can concentrate better on their allotted task than in a tightly coupled system where modules are highly reliant on each other. 

What is Coupling?

Types of Coupling 

  1. No direct Coupling
    As the name suggests, no direct connection formed between the modules in this type of Coupling. No Direct Coupling is the most desired Coupling as modules are unrelated and can focus on their assigned task.
     
  2. Data Coupling
    In this type of Coupling, one or more data is shared between the modules. The data could be of int or float type. Sharing of data between modules results in interdependency and thus difficulty focussing on their own assigned task.
     
  3. Content Coupling 
    Defined as the worst form of Coupling as control flow or program code is shared between the modules involved results in control of one function by another. One module depends on another module implementation. This type of Coupling needs to be avoided from our software system at any cost.
     
  4. Control Coupling
    If involved modules communicate by passing control information to each other, then such a coupling is called control coupling. One function directs the flow of another process, i.e. data from one function controls the execution of another function.  
     
  5. External Coupling
    This type of Coupling is formed if the involved module shares an external data format. In this type of Coupling, the related modules share a structure, an interface or a communication protocol.
     
  6. Common Coupling
    This type of Coupling involves modules that share common data with the help of global data items. Any change in the global data traces back changes to every module which accesses the data.
     
  7.  Stamp Coupling
    Also known as Data Structure coupling, a module shares a complete data structure with another module that uses only some part of the data that is too different. 

What is Cohesion?

Cohesion tells us the degree to which elements of a particular module are functionally related to each other. It measures the degree to which different elements of the module are directed to perform the same task and are contained in a single component. 

What is Cohesion?

It helps us measure the strength of a module, i.e. how well the aspects of modules are interrelated to each other. e.g. a system with high cohesion has elements that are highly related to each other, which helps in performing the assigned task much better than a system with low cohesion where the module elements are less related. 
 

Also see,  V Model in Software Engineering

Types of Cohesion

  1. Functional Cohesion
    This type of cohesion exists if elements inside the modules have a single goal. The elements of the modules work in coordination to stay focused on the task assigned. They only perform the activities which are essential for the completion of the task assigned.  
     
  2. Sequential Cohesion
    Sequential cohesion maintains the sequence of activity. The outcome data of one feature works as an input to others. It helps to deliver good Coupling and makes maintenance easy due to a well-defined sequence of events.
     
  3. Logical Cohesion
    In logical cohesion, elements are related logically, not functionally. Logical cohesion exists if all the functions within a module execute a similar operation. Such modules are said to be logically cohesive.
     
  4. Communicational Cohesion
    Two aspects of the modules working on the same input data and contributing to the same output have communicational cohesion. Two elements of modules are grouped as they operate on the same data.
     
  5. Temporal Cohesion
    In this type of cohesion where a module includes functions that are associated by the fact of execution at the same time simultaneously. The module associated with this cohesion has to execute all the tasks simultaneously at the same time.
     
  6. Procedural Cohesion
    In this type of cohesion, the purpose of the involved module is all parts of a procedure in which to achieve a particular goal, a sequence of steps has to be carried out.
     
  7. Coincidental Cohesion
    Elements of the modules are unrelated. This is the worst type of cohesion possible as only a few elements of the modules are related, if related at all.

Difference Between Coupling and Cohesion

Coupling and cohesion are two crucial terms in Software Engineering. Both measure the degree of dependencies just on different parts of the system. So it is vital to understand the essential difference between the two.

CouplingCohesion
  • It is referred to as inter-module binding.
  • It is referred to as Intra module binding.
  • It shows relative independence between the module.
  • It shows the relative functional strength of the module.
  • A sound software system should have low Coupling (since the loosely coupled system has modules less dependent on each other and hence able to focus more on the assigned task).
  • A sound software system should have high cohesion(high cohesion indicates high functional strength of modules, that is, elements are connected intensely and hence able to focus more on the task assigned).
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Advantages of low coupling

  • Enhanced Maintainability: It is simpler to maintain and modify the system when changes made to one module have little effect on other modules. 
     
  • Reusability: Without requiring significant changes, modules can be utilized again in many settings. 
     
  • Enhanced Scalability: The flexibility and scalability of the system are enhanced by the independent addition or modification of its components. 
     
  • Improved Testability: Isolation testing of modules enables more precise and effective testing procedures.

Advantages of high cohesion

  • Enhanced Maintainability: High cohesion modules are simpler to comprehend, update, and alter. 
     
  • Reusability: Modules that are well-defined can be used again in different situations without requiring significant changes. 
     
  • Enhanced Robustness: Errors and unexpected side effects are less likely to occur when module boundaries are clearly defined. 
     
  • Improved Testability: It is simpler to test highly cohesive modules separately, which results in testing procedures that are more efficient.

Disadvantages of high coupling

  • Complexity of Maintenance: High coupling makes maintenance of the system more difficult because it requires changes to be made to several modules, which raises the chance of mistakes. 
     
  • Limited Reusability: Flexibility and efficiency are hampered by tightly connected modules' reduced reusability in a variety of contexts without considerable adjustments. 
     
  • Scalability Issues: Extensive interdependencies between modules can make a system less scalable and make it more difficult to add or modify components on their own.
     

Disadvantages of low cohesion

  • Decreased Maintainability: Because of their scattered and unconnected functionalities, modules with low cohesion are more difficult to comprehend and maintain, which raises the possibility of mistakes and inconsistencies. 
     
  • Reduced Reusability: Because low-cohesion modules lack a clear, well-defined purpose and may contain unrelated functionalities, they are less reusable in many situations. 
     
  • Reduced Robustness: When disparate functionalities conflict with one another, there may be unanticipated side effects and errors.

Frequently Asked Questions

What is coupling and cohesion in software engineering?

Coupling and cohesion are fundamental concepts in software engineering, assessing the effectiveness of a software system's design. Cohesion and coupling is very essential to build maintainable, scalable, and resilient software applications. Coupling is the degree to which two modules are interrelated. Cohesion is the degree to which elements of a particular module are functionally related.

What are the 4 types of cohesion?

The four types of cohesion are: Functional Cohesion, Sequential Cohesion, Communicational Cohesion, and Temporal Cohesion. 

What is called coupling?

The degree of interdependence between a system's modules or components is referred to as coupling. It determines how interdependent or dependent each system module is on the others.

What is coupling in oops?

The term coupling in object-oriented programming (OOP) describes the level of interdependence or relationship among classes or objects. It determines the degree to which classes are related to one another and how each class depends on the others to achieve tasks.

What is the basic difference between Coupling and cohesion?

Coupling and cohesion refer to two completely different things. Coupling is referred to as inter-module binding (it shows the relation between modules), and cohesion, on the other hand, refers to as Intra module binding(it shows relationships within the modules). Coupling shows relative independence between the module, while cohesion shows relative functional strength of the module.

Conclusion

In the article, we have extensively discussed the design phase of the software development life cycle. Along with that, We have also explored the two essential terminologies of software designing, i.e. Coupling and cohesion, their type, differences, and some characteristics of good software.

We hope that this blog has helped you enhance your knowledge regarding software engineering. If you would like to learn more about such content and practice some quality questions that require you to excel your preparations a notch higher. In that case, you can visit our Guided Path in  Coding Ninjas Studio.To be more confident in data structures and algorithms, try out our DS and Algo Course. Until then, All the best for your future endeavours, and Keep Coding.

 

Next article
Entity-Relationship Diagrams
Live masterclass