🔌 Software Design Principles · Core Principles
Loose Coupling
Components should know as little as necessary about each other's internals.
Changing one component should not force many unrelated changes.
OrderService uses an IPaymentService interface instead of vendor-specific code everywhere.
💡 Like a wall socket: any appliance plugs in through the same shape, so you can swap the lamp without rewiring the house.
💡 Why it matters
Tightly coupled code means a change in one place ripples into many others, making every edit risky. When components depend on small contracts instead of each other's details, you can replace, test or upgrade one piece without disturbing the rest. Loose coupling is what lets a big system keep evolving safely.
🛠️ How to achieve it
⚠️ Signs of trouble
- •A small change forces edits across many unrelated files.
- •Vendor-specific details are hard-coded throughout the app.
- •You cannot test a component without its real neighbors.
- •Classes know far too much about each other's internals.
🎯 Quick check
Score: 0/3Three questions to test the idea.
1. What makes components loosely coupled?
Answer: They depend on small contracts, not each other's internals
Talking through a contract lets one piece change without forcing changes in the others.
2. Why use an interface like IPaymentService instead of vendor code everywhere?
Answer: So you can swap the vendor without touching the whole app
Depending on the interface means the vendor detail lives in one place and is easy to replace.
3. What is a sign of tight coupling?
Answer: A small change forces edits across many unrelated files
Ripple-effect changes across many files show components know too much about each other.
