codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🧩

OOP Concepts

23 chapters

1Procedural vs Object-Oriented2Classes, Objects, & Instantiation3Constructors & Destructors4Static Members & Methods5Encapsulation & Access Modifiers6Data Abstraction7Inheritance Types (Single, Multiple)8Compile-Time Polymorphism (Overloading)9Polymorphism & Interfaces10Run-Time Polymorphism (Overriding)11Virtual Functions & V-Tables12Interfaces & Abstract Classes13Generic Programming (Templates & Generics)14Exception Handling in OOP15SOLID Design Principles16Composition over Inheritance17Coupling & Cohesion18UML Diagrams Basics19Creational Patterns (Singleton, Factory)20Structural Patterns (Adapter, Decorator)21Behavioral Patterns (Observer, Strategy)22MVC Architecture Pattern23Object Serialization & Cloning
SubjectsOOP Concepts

Coupling & Cohesion

Updated 2026-04-24
2 min read

Coupling & Cohesion

Coupling and Cohesion are the two most important metrics for evaluating the quality of a software design. Good design strives for low coupling and high cohesion.

1. Coupling (How tightly classes depend on each other)

Coupling measures the degree of interdependence between software modules. Low coupling means modules are independent; changes in one module have minimal impact on others.

Types (from worst to best):

  • Content Coupling: Module A directly accesses internal data of Module B. The worst form. Changing B's internal structure breaks A.
  • Common Coupling: Multiple modules share a global variable. Any module can modify it, making debugging nightmarish.
  • Control Coupling: Module A passes a control flag to Module B that tells B which logic to execute. A dictates B's behavior.
  • Stamp Coupling: Module A passes an entire data structure to Module B, but B only uses a few fields. B unnecessarily depends on A's data structure.
  • Data Coupling: Modules communicate by passing only the specific primitive data they need. The best form.
  • Message Coupling: Modules communicate only through method calls with no parameters (or through events/messages). The loosest coupling.

2. Cohesion (How focused a class is on a single purpose)

Cohesion measures how closely related the responsibilities within a single module are. High cohesion means a module does one thing well.

Types (from worst to best):

  • Coincidental Cohesion: A class contains completely unrelated functions grouped together for no logical reason. The worst.
  • Logical Cohesion: Functions are grouped because they fall into the same general category, even though they are otherwise unrelated. A Utils class with formatDate(), parseJSON(), and calculateTax().
  • Temporal Cohesion: Functions are grouped because they are executed at the same time (e.g., all initialization functions in one class).
  • Procedural Cohesion: Functions are grouped because they always execute in a specific sequence.
  • Functional Cohesion: Every function in the module contributes to a single, well-defined task. The best.

3. The Goal

MetricGoalExample
CouplingLOWClasses communicate through interfaces, not concrete implementations
CohesionHIGHEach class has a single, focused responsibility (SRP)

A class with high cohesion and low coupling is easy to understand in isolation, easy to test, easy to reuse, and easy to modify without breaking other parts of the system.



PreviousComposition over InheritanceNextUML Diagrams Basics

Recommended Gear

Composition over InheritanceUML Diagrams Basics