why interfaces are useful — especially in JDBC.
We’ll do this in two steps:
✅ Step 1: Without Interface (Tightly Coupled – Bad Practice)
❌ Problem:
This code depends directly on MySQLConnection.
If tomorrow you switch to PostgreSQL, you'd have to change code in main() and everywhere else.
✅ Step 2: With Interface (Loosely Coupled – Good Practice)
✅ Benefits Shown Here
🔁 Real-World JDBC Example
In JDBC, you do:
Connection conn = DriverManager.getConnection(...);
But this Connection is an interface. The actual object is:
com.mysql.cj.jdbc.ConnectionImpl
So you're writing generic JDBC code that works for any database driver (MySQL, Postgres, Oracle), thanks to interfaces!
✅ Summary
Interfaces define what should be done, not how.
Using interfaces allows swappable implementations (e.g., MySQL, PostgreSQL).
JDBC uses this approach: you code to java.sql.Connection, and drivers implement it.
Would you like a diagram of this concept (interface → implementation → runtime behavior) for visual learners?