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:
Public Interface IDatabase Public Sub Connect() Public Sub Disconnect() 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:
Public Class MSSQL Implements IDatabase Public Sub Connect() ' Some code here End Sub Public Sub Disconnect() ' Some code here End Sub End Class Public Class Oracle Implements IDatabase Public Sub Connect() ' Some code here End Sub Public Sub Disconnect() ' Some code here End Sub End Class




Reply With Quote