All an interface is...in its simplest form...is the implementation for a class. One of the big benefits (to me) that interfaces provide is de-coupling your code...essentially it makes your code less dependent upon other classes.
Example situation.
Say you have 3 different currencies, US Dollar, Indian Rupee, and the Euro. Without an interface you would have this code.
UsDollar currency1 = new UsDollar();
To work with the respective classes. If you wanted to swap out the UsDollar for a Rupee, you'd have to swap out the code/make any changes necessary to support the next class
Rupee currency1 = new Rupee();
But by using an interface, you can de-couple the dependency upon the specific class being used and use the interface instead (similar to how your example snippet you posted).
So Say you have an interface that implements an integer of CurrencyValue and a method of Exchange Rate
public interface ICurrency
{
int CurrencyValue { get; set; }
void ExchangeRate(double percent);
}
You would then have the following 3 classes that inherit from the Interface. Remember, if a class inherits from that interface, they must implement the same as what the interface implements.
public class UsDollar : ICurrency
{
public int CurrencyValue { get; set; }
public void ExchangeRate(double percent)
{
Console.WriteLine("Your Exchange Rate for Us Dollar is {0}", CurrencyValue * percent);
}
}
public class Euro : ICurrency
{
public int CurrencyValue { get; set; }
public void ExchangeRate(double percent)
{
Console.WriteLine("Your Exchange Rate for Euro is {0}", CurrencyValue * percent);
}
}
public class Rupee : ICurrency
{
public int CurrencyValue { get; set; }
public void ExchangeRate(double percent)
{
Console.WriteLine("Your Exchange Rate for Rupee is {0}", CurrencyValue * percent);
}
}
So the by changing your usage from
Rupee currency1 = new Rupee();
To
ICurrency currency1 = new Rupee();
Your code that is using this class no longer cares if it is a Rupee, Us Dollar, Euro...or whatever other currency classes you end up creating.
Interfaces can also provide value in various design patterns as well (factor pattern).
Example Usage:
ICurrency currency1 = new UsDollar();
ICurrency currency2 = new Euro();
ICurrency currency3 = new Rupee();
currency1.CurrencyValue = 10;
currency2.CurrencyValue = 13;
currency3.CurrencyValue = 16;
currency1.ExchangeRate(1.1);
currency2.ExchangeRate(1.6);
currency3.ExchangeRate(1.5);
So to answer your question
IModelDoc2 swModel;
This should specifically be creating a new object of some class type (in my example this would be same as ICurrency currency1 = new UsDollar();). So somewhere in your code you would be assigning the value to swModel which would be some class/type that inherits from IModelDoc2.
Hope this helps/clarifies things for you.
But to read up on interfaces i would suggest following links:
http://msdn.microsoft.com/en-us/library/87d83y5b%28v=vs.80%29.aspx[
^]
Interfaces in C# (For Beginners)[
^]
Abstract Class versus Interface[
^]
When To Use Interfaces[
^]
There is plenty of other reading, but those are just a few other links