Open In App

Differences between Coupling and Cohesion - Software Engineering

Last Updated : 03 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Coupling and Cohesion are two key concepts in software engineering that are used to measure the quality of a software system’s design. Both coupling and cohesion are important factors in determining the maintainability, scalability, and reliability of a software system. High coupling and low cohesion can make a system difficult to change and test, while low coupling and high cohesion make a system easier to maintain and improve.

Coupling-vs-Cohesion
Coupling vs Cohesion

What is Cohesion?

Cohesion refers to the degree to which elements within a module work together to fulfill a single, well-defined purpose. High cohesion means that elements are closely related and focused on a single purpose, while low cohesion means that elements are loosely related and serve multiple purposes.

Types of Cohesion

The following are the types of cohesion:

  1. Functional Cohesion
  2. Procedural Cohesion
  3. Temporal Cohesion:
  4. Sequential Cohesion.
  5. Layer Cohesion.
  6. Communication Cohesion.
cohesion
Types of Cohesion

What is Coupling

Coupling refers to the degree of interdependence between software modules. High coupling means that modules are closely connected and changes in one module may affect other modules. Low coupling means that modules are independent, and changes in one module have little impact on other modules.

Types of Coupling

Following are the types of Coupling:

  1. Data Coupling
  2. Stamp Coupling
  3. Control Coupling
  4. External Coupling
  5. Common Coupling
  6. Content Coupling


coupling
Types of Coupling

Differences between Coupling and Cohesion

The differences between cohesion and coupling are given below:

Aspect

Cohesion

Coupling

Definition

Cohesion refers to the degree to which elements within a module work together to fulfill a single, well-defined purpose.

Coupling refers to the degree of interdependence between software modules. High coupling means that modules are closely connected and changes in one module may affect other modules.

Module Dependency

Cohesion is the concept of an intro-module.

Coupling is the concept of inter-module.

Purpose

Cohesion represents the relationship within a module.

Coupling represents the relationships between modules.

Quality

Increasing cohesion is good for software.

Increasing coupling is avoided for software.

Focus

Cohesion represents the functional strength of modules.

Coupling represents the independence among modules.

Relationship

Highly cohesive gives the best software.

Whereas loosely coupling gives the best software.

Example

In cohesion, the module focuses on a single thing.In coupling, modules are connected to the other modules.

Creation

Cohesion is created between the same module.Coupling is created between two different modules.

Types

Types of Cohesion

  1. Functional Cohesion.
  2. Procedural Cohesion. 
  3. Temporal Cohesion.
  4. Sequential Cohesion.
  5. Layer Cohesion.
  6. Communication Cohesion.

Types of Coupling

  1. Data Coupling
  2. Stamp Coupling
  3. Control Coupling
  4. External Coupling
  5. Common Coupling
  6. Content Coupling

Example of High Cohesion and Low Coupling

Below diagram shows the example of high cohesive and low coupling:

Untitled-Diagramdrawio
High Cohesive and Low Coupling

Explanation

High Cohesion: User Module

The User Module is designed to handle all user-related functionalities:

  • Attributes: It has attributes like id, name, and email.
  • Functions: It includes functions such as register(), login(), and logout().

Why is it high cohesion?

  • Single Purpose: All the functions in the User Module are related to managing users. This means everything in this module is focused on one specific task - handling user operations.

Low Coupling: Book and Member Modules

The Library System consists of two separate modules: Book and Member.

  • Book Module:
    • Attributes: It has attributes like title and author.
    • Functions: It includes functions such as addBook() and removeBook().
  • Member Module:
    • Attributes: It has attributes like memberId and memberName.
    • Functions: It includes functions such as addMember() and removeMember().

Why is it low coupling?

  • Independent Modules: The Book and Member modules operate independently. They have their own specific functions and attributes and don’t need to know the internal workings of each other.
  • Minimal Interaction: The only interaction is through simple actions like borrowing a book or managing memberships, but they don't rely on each other for their main tasks.

Important Questions on Coupling vs Cohesion

1. In the context of modular software design, which one of the following combinations is desirable? [ ISRO CS 2017 - May ]

(A) High cohesion and high coupling

(B) High cohesion and low coupling

(C) Low cohesion and high coupling

(D) Low cohesion and low coupling

Solution: The Correct answer is (B)

2. A software design is highly modular if: [ UGC NET CS 2015 Jun - III ]

(A) cohesion is functional and coupling is data type.

(B) cohesion is coincidental and coupling is data type.

(C) cohesion is sequential and coupling is content type.

(D) cohesion is functional and coupling is stamp type.

Solution: The Correct answer is (A)

3. Which of the following statement(s) is/are true with respect to software architecture ? S1 : Coupling is a measure of how well the things grouped together in a module belong together logically. S2 : Cohesion is a measure of the degree of interaction between software modules. S3 : If coupling is low and cohesion is high then it is easier to change one module without affecting others. [ UGC NET CS 2017 Jan - II ]

(A) Only S1 and S2

(B) Only S3

(C) All of S1, S2 and S3

(D) Only S1

Solution: The Correct answer is (B)


Next Article

Similar Reads