Interface is a way to described methods for a class without really implementing them.
I'll explain with an example:
First, we shall define the interface IDataProvider:
public interface IDataProvider
{
public void SetData(DataTable dataToSet);
public DataTable GetData();
}
As you can see, the definition is like class definition, only replacing the class with interface.
In the interface, I described 2 methods: SetData and GetData, the interface contains only the signature of the methods and not the implementation.
Now, I'm defining a class that implements this interface that uses MySql database:
public class MySqlProvider : IDataProvider
{
#region IDataProvider Members
public void SetData(System.Data.DataTable dataToSet)
{
// Fills the data base with the data table sent
}
public System.Data.DataTable GetData()
{
// Returns the data table from the data base
}
#endregion
}
And the other implemention:
public class SyBaseProvider : IDataProvider
{
#region IDataProvider Members
public void SetData(System.Data.DataTable dataToSet)
{
// Fills the data base with the data table sent
}
public System.Data.DataTable GetData()
{
// Returns the data table from the data base
}
#endregion
}
Offcourse, you can write what ever you want in this classes: methods memebers etc, but the GetData and SetData methods must be defined.
Now, to use this interface,
We declare the interface:
IDataProvider provider;
We use the implementaion we need based on a term:
if(MSSQL == true)
provider = new MySqlProvider();
else
provider = new SyBaseProvider();
And we can call the methods:
provider.SetData(...);
provider.GetData();
when we need them, the work will be done acording to the implementaion that was defined.
I requmened you to read about interface, it can help you a lot, also, check out the abstract class, that is like inerface but gives the option to write some code on the base class (that is common to all imlementions).