I need some clarification on when to use an interface and it's advantages. I believe the use of an interface is polymorphism, but what are the advantages of using an interface?

For example suppose you have an application that needs to connect to an Oracle and MSSQL Server database, so you create an interface that handles the basic interactions with a database.

VB Code:
  1. Public Interface IDatabase
  2.     Public Sub Connect()
  3.     Public Sub Disconnect()
  4. End Interface

Since both the MSSQL and Oracle databases may handle the connection, update, and delete processes differenlty you have to create two different classes one for each database system. Each class needs to implement all the methods in the interface.

This is where I am getting confused - what is the role of an interface? Is it just a model that they should follow? Or am I way off?

VB Code:
  1. Public Class MSSQL Implements IDatabase
  2.     Public Sub Connect()
  3.       ' Some code here
  4.     End Sub
  5.     Public Sub Disconnect()
  6.       ' Some code here
  7.     End Sub
  8. End Class
  9.  
  10. Public Class Oracle Implements IDatabase
  11.     Public Sub Connect()
  12.       ' Some code here
  13.     End Sub
  14.     Public Sub Disconnect()
  15.       ' Some code here
  16.     End Sub
  17. End Class