Posts

Showing posts from November, 2025

🔍 What is Tight Coupling and Loose Coupling? (Android Developer Explanation)

✅  Tight Coupling Two classes/components are tightly coupled when they depend on each other directly. If one changes, the other must also change. It reduces flexibility and reusability. 📌 Example (Bad Practice – Tight Coupling) class UserRepository { fun getUser() = "Android Developer" } class UserViewModel { private val repository = UserRepository() // Direct object creation → TIGHT COUPLING fun printUser() { println(repository.getUser()) } } 🔴 Problems: UserViewModel cannot work without UserRepository Hard to unit test (cannot inject mock repo) If repository changes, viewmodel breaks Not reusable ✅ Loose Coupling Two classes are loosely coupled when they depend on abstractions (interfaces) instead of concrete classes. You can replace dependency without modifying main logic → more flexible. 📌 Example (Good Practice – Loose Coupling with DI) interface UserRepository { fun getUser(): String } class UserRepository...