0
0
Software Engineeringknowledge~6 mins

Coupling and cohesion in Software Engineering - Full Explanation

Choose your learning style9 modes available
Introduction
When building software, parts need to work together smoothly without being too dependent or too scattered. Finding the right balance helps make programs easier to understand, change, and fix.
Explanation
Coupling
Coupling describes how much one part of a program relies on another. If parts are tightly connected, a change in one can cause problems in others. Loose coupling means parts work more independently, making the system easier to maintain.
Loose coupling means parts depend less on each other, improving flexibility.
Types of Coupling
Coupling ranges from tight to loose. Tight coupling happens when parts share many details or data directly. Loose coupling happens when parts communicate through simple, clear interfaces without knowing internal details.
Using simple interfaces reduces coupling and improves system design.
Cohesion
Cohesion measures how closely related the tasks within a single part are. High cohesion means a part does one clear job well. Low cohesion means a part tries to do many unrelated things, making it harder to understand and maintain.
High cohesion means a part focuses on a single task, making it clearer and easier to manage.
Types of Cohesion
Cohesion can be functional, where all tasks contribute to one function, or it can be weaker, like when tasks are only loosely related. Strong cohesion helps keep code organized and easier to test.
Functional cohesion leads to better organized and more reliable code.
Real World Analogy

Imagine a team working on a project. If team members depend too much on each other's detailed work, delays happen when one person changes their part. But if each member focuses on their own clear task and communicates simply, the project flows smoothly.

Coupling → Team members depending heavily on each other's detailed work
Loose Coupling → Team members working independently and sharing only necessary information
Cohesion → Each team member focusing on a single clear task
Functional Cohesion → A team member whose tasks all contribute directly to one goal
Diagram
Diagram
┌─────────────┐       ┌─────────────┐
│   Module A  │──────▶│   Module B  │
└─────────────┘       └─────────────┘
      │                     │
      │ Loose Coupling       │ Tight Coupling
      ▼                     ▼
┌─────────────┐       ┌─────────────┐
│  Single Job │       │ Multiple Jobs│
│ (High Coh.) │       │ (Low Coh.)  │
└─────────────┘       └─────────────┘
This diagram shows modules with different coupling and cohesion levels: loose vs tight coupling and high vs low cohesion.
Key Facts
CouplingThe degree to which one module depends on another.
Loose CouplingModules interact through simple interfaces with minimal knowledge of each other.
Tight CouplingModules are highly dependent on each other's internal details.
CohesionHow closely related the responsibilities of a single module are.
High CohesionA module performs a single, well-defined task.
Low CohesionA module handles unrelated tasks, making it complex and hard to maintain.
Common Confusions
Believing tight coupling is always bad.
Believing tight coupling is always bad. Tight coupling can be acceptable in small, simple programs but causes problems as systems grow and change.
Thinking cohesion and coupling are the same.
Thinking cohesion and coupling are the same. Cohesion is about how focused a single part is, while coupling is about how much parts depend on each other.
Summary
Loose coupling means parts of a program depend less on each other, making changes easier.
High cohesion means each part focuses on one clear task, improving clarity and maintenance.
Good software design balances low coupling with high cohesion for better flexibility and organization.