Types of Coupling: From Tight to Loose
You'll learn: How different types of coupling create varying levels of dependency between components, from worst to best.
Now that you understand coupling affects how tightly components depend on each other, let's explore the specific types of coupling that exist. Think of coupling like different ways people can be connected—some relationships make you completely dependent on someone else's decisions, while others give you independence.
Content Coupling (Worst)
One component directly modifies or relies on the internal workings of another. Like reaching into someone else's pocket without permission—extremely invasive and fragile.
Common Coupling
Multiple components share the same global data. If one changes that data, everyone is affected. Imagine roommates all using the same unlabeled milk carton—chaos ensues when someone changes what's inside.
External Coupling
Components depend on externally imposed formats or protocols (like file formats or communication protocols). Changes to these external standards force multiple components to update.
Control Coupling
One component controls another's behavior by passing flags or commands. Component A tells Component B how to do its job, creating unnecessary knowledge about B's internal logic.
Stamp Coupling
Components share a data structure but each only uses part of it. Better than sharing everything, but still creates unnecessary dependencies on the whole structure's shape.
Data Coupling (Best)
Components only share the minimal necessary data through parameters. Like ordering at a restaurant—you tell the kitchen what you want, not how to cook it. This is our goal: clean, minimal dependencies.
Key Takeaway: Coupling exists on a spectrum from tight (content) to loose (data). Aim for data coupling—where components share only necessary information and remain independent—to create flexible, maintainable designs.